在一天晚上一个面包店打折,买1个面包打9折,2个面包打8折,3个面包打7折。编写一个python程

2025-03-25 03:13:03
推荐回答(2个)
回答1:

#set the variables
amount = 0
money_saved = 0
total_cost = 0
price = input("Enter the price of the bread until entered you entered 0: ")

#while statement
while price > 0:
total_cost = total_cost + price
amount +=1
price = input("Enter the price of the bread untiled you entered 0: ")
if amount < 3:
total_off = total_cost * (1- amount * 0.1)

#if the amount of the bread is more than 3
else:
total_off = total_cost * 0.7
money_saved = total_cost - total_off

#print the total cost, and money saved
print "Total cost after the discount is: ", total_off
print "You saved: ", money_saved

回答2:

0