mercredi 2 octobre 2019

Is there a way to save results from a for loop besides using print()?

I am trying to get the results from the my For Loop and if loop. The two results I want are the optimal price and optimal product when supply=demand.

def supply(p): """ This function calculates the supply of the video game as a function of price :param P: Ideal price of the game :return: The result of the calculated supply """ supply = 500 + 90 * p return supply

def demand(p): """ This function calculates the demand as a function of price :param P: Ideal price of the game :return: the result of the calculated demand """ demand = 10000 - 35 * p return demand

for p in range(10 , 161, 1): demand_result = supply(p) supply_result = demand(p) print('Price is:', p , 'Demand # is:' , demand_result , 'Supply # is:' , supply_result)

if demand_result == supply_result:
    p = optimal_price
    supply_result = optimal_product

print('The optimal price is ${:.2f}'.format(optimal_price))

The expected result is price = $76.00 and product = 7340

Aucun commentaire:

Enregistrer un commentaire