我正在制作三明治店的程序,用户要求三明治,然后程序会告诉你改变。 我是python的新手,我对它有一点了解。
这是我的代码:
print "Welcome to the sandwich shop!"
name = raw_input("What is your name?")
print "The price of a sandwich is 0.5 dollars"
print "The price of a cookie is 0.05 dollars"
print "The price of a mint is 0.01 dollars"
sandwich = int(raw_input("How many sandwiches do you want?"))
cookie = int(raw_input("How many cookies do you want?"))
mint = int(raw_input("How many mints do you want?"))
sandwich_price = 0.5
cookie_price = 0.05
mint_price = 0.01
sandwich_price_total = sandwich * sandwich_price
cookie_price_total = cookie * cookie_price
mint_price_total = mint * mint_price
total_order = sandwich_price_total + cookie_price_total + mint_price_total
print "The order will be %r dollars!" % total_order
penny = 0.01
nickel = 0.05
dime = 0.10
quater = 0.25
dollar = 1
five = 5
twenty = 20
fifty = 50
print "Please pay in cash."
pay = int(raw_input("Insert your money!"))
change = pay - total_order
coins = [penny, nickel, dime, quater, dollar, five, twenty, fifty]
def change(n, coins_avaliable, coins_so_far):
if sum(coins_so_far) == change:
yield coins_so_far
elif sum(coins_so_far) > change:
pass
elif coins_avaliable == []:
pass
else:
for c in change(change, coins_avaliable[:], coins_so_far + [coins_avaliable]):
yield c
for c in change(change, coins_avaliable[1:], coins_so_far):
yield c
solution = [s for s in change(n, coins, [])]
for s in solution:
print s
什么都没发生!
请帮忙!