2016-12-13 33 views
-2

我正在做一個三明治店的計劃。三明治店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 

我收到此錯誤:

error 預先感謝您!

+1

你的許多作業都是向後的。請找到並按照介紹[教程](http://sopython.com/wiki/What_tutorial_should_I_read%3F)。 – jonrsharpe

+1

在賦值(即'='運算符)中,您分配的內容應位於左側。所以,例如,'sandwich * sandwich_price = sandwich_price_total'應該是'sandwich_price_total = sandwich * sandwich_price'。 –

+0

此外,原始輸入返回一個字符串,所以比較應該是字符串「信用」和「現金」而不是術語。 (這會給自己的錯誤) – ANVGJSENGRDG

回答

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 

註釋說明大部分錯誤。

花點時間比較一下代碼,看看發生了什麼變化,以便將來也不會犯同樣的錯誤。

並再次歡迎!

相關問題