三明治店 python

Sandwich Shop python

我正在制作一个三明治店的程序。

我是 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

我收到这个错误:

提前谢谢你!

欢迎来到 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

主要评论 post 解释了大部分错误。

花点时间比较一下代码,看看有什么变化,这样以后就不会犯同样的错误了。

再次欢迎!