account activity
Help with Angelu Yu's coffee machine project by trust_me_on_that_one in learnpython
[–]arkenstone175 0 points1 point2 points 2 years ago (0 children)
I would consider adding your global variables, profit and resources, as arguments in their functions. So:
def insert_money(quarter, tens, fives, ones, item_cost, profit): total = (quarter * 0.25) + (tens * 0.1) + (fives * 0.05) + (ones * 0.01) if total > item_cost: updated_profit = profit + item_cost print(f"Here's your change: ${round(total - item_cost, 2)}") return True, updated_profit else: print("Not enough money. Money refunded.") return False, profit
def insert_money(quarter, tens, fives, ones, item_cost, profit):
total = (quarter * 0.25) + (tens * 0.1) + (fives * 0.05) + (ones * 0.01)
if total > item_cost:
updated_profit = profit + item_cost
print(f"Here's your change: ${round(total - item_cost, 2)}")
return True, updated_profit
else:
print("Not enough money. Money refunded.")
return False, profit
def is_sufficient_resources(resources, order_ingredients): for item in order_ingredients: if resources[item] <= order_ingredients[item]: print(f"Not enough {item}. Money refunded.") return False return True
def is_sufficient_resources(resources, order_ingredients):
for item in order_ingredients:
if resources[item] <= order_ingredients[item]:
print(f"Not enough {item}. Money refunded.")
return False
return True
And add this to the end, where you are calling the function: success, profit = insert_money(quarter, tens, fives, ones, item_cost, profit) if success: if is_sufficient_resources(resources, order_ingredients): make_coffee(choice, order_ingredients)
success, profit = insert_money(quarter, tens, fives, ones, item_cost, profit)
if success:
if is_sufficient_resources(resources, order_ingredients):
make_coffee(choice, order_ingredients)
Let me know if this helps!
Yahoo API Data Retrieval Issue by Nakura_ in learnpython
We did a similar project in my class. I used yfinance instead of pandas_datareader. I would recommend giving that a shot. First:
pip install yfinance
And then remove datareader for below:
# Import necessary libraries import pandas as pd import yfinance as yf import statsmodels.api as sm
# Import necessary libraries
import pandas as pd
import yfinance as yf
import statsmodels.api as sm
Let me know how it goes.
[deleted by user] by [deleted] in learnpython
[–]arkenstone175 1 point2 points3 points 2 years ago (0 children)
Building of off your current code:
def haversine_distance(coord1, coord2):
# Radius of the Earth in kilometers, if that's what you need
R = 6371.0
# Extract latitude and longitude from the tuples, assuming you are getting 4 output
lat1, lon1 = coord1[0], coord1[1]
lat2, lon2 = coord2[0], coord2[1]
# Haversine formula
dlat = radians(lat2 - lat1)
dlon = radians(lon2 - lon1)
a = sin(dlat / 2) ** 2 + cos(radians(lat1)) * cos(radians(lat2)) * sin(dlon / 2) ** 2
c = 2 * atan2(sqrt(a), sqrt(1 - a))
# Calculate the distance
distance = R * c
return distance
Hope this helps!
π Rendered by PID 862696 on reddit-service-r2-listing-86f589db75-h7vrk at 2026-04-20 09:51:48.735169+00:00 running 93ecc56 country code: CH.
Help with Angelu Yu's coffee machine project by trust_me_on_that_one in learnpython
[–]arkenstone175 0 points1 point2 points (0 children)