我正在制作三明治店的节目。
我是python的新手,所以我需要一些帮助!
print "Welcome to the sandwich shop!"
name = raw_input("What is your name?")
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
print sandwich_price + cookie_price + mint_price
sandwich * sandwich_price = sandwich_price_total
cookie * cookie_price = cookie_price_total
mint * mint_price = mint_price_total
sandwich_price_total + cookie_price_total + mint_price_total = total_order
print ("THe order will be %r dollars!") , total_order
penny = 0.01
nickel = 0.05
dime = 10
quater = 25
dollar = 1
print "Please pay in cash or credit card!"
question1 = raw_input("> ")
if question1 == credit:
print "%r you got %r dollars from your account." % (name, total_order)
if question1 == cash:
print "You paid %r dollars!" % total_order
print "Thank you for coming %r" % name
我收到此错误:
答案 0 :(得分:2)
欢迎来到python社区。 你的代码,纠正了错误:
print "Welcome to the sandwich shop!"
name = raw_input("What is your name?")
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
print str(sandwich_price + cookie_price + mint_price)
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 = .10
quater = .25
dollar = 1
print "Please pay in cash or credit card!"
question1 = raw_input("> ").lower()#lets you answer Credit as well as credit
if question1 == "credit":
print "%r you got %r dollars from your account." % (name, total_order)
if question1 == "cash":
print "You paid %r dollars!" % total_order
print "Thank you for coming %r" % name
主帖上的评论解释了大部分错误。
花点时间比较一下代码,看看有什么变化,以便将来犯同样的错误。
再次欢迎!