2012-09-24 14 views
-1

Possible Duplicate:
Python 3.2.3 programming…Almost had it working爲什麼不Python的這項工作3.2.3

x = float(input("What is/was the cost of the meal?")) 
y = float(input("What is/was the sales tax?")) 
z = float(input("What percentage tip would you like to leave?")) 

print ("Original Food Charge: ${}" 
.format(x))) 
print ("Sales Tax: ${}" 
.format((y/100)*x))) 
print ("Tip: ${}" 
.format(x*(z/100))) 
print ("Total Charge For Food: ${}" 
.format(x+((y/100)*x)+((z/100)*x))) 

輸出錯誤:

線10條,在 語法錯誤:.format(X))):行1015

有人報告說,這在他們早期版本的python(我認爲是v2.6)中有效。我正在使用後來的3.2.3版本,並且絞盡腦汁地想知道爲什麼這個版本無法使用。這對我有意義,請讓我注意。

+5

編輯你原來的問題,,問在同一問題在不同的問題不會幫助... – avasal

+0

我編輯了我原來的問題,它是完全更新。它似乎被忽略了,正在回答我的問題的程序員之一建議我重新發布我的代碼以進行分析。 – user1693293

+0

@ user1693293現在按預期工作嗎? –

回答

2

.format(x*(z/100))後面有一個括號,屬於前面的print

它應該是:

print ("Tip: ${}".format(x*(z/100))) 

UPDATE:不知道,如果你得到它的工作或沒有,這裏是你的固定不平衡括號後的完整代碼...

x = float(input("What is/was the cost of the meal?")) 
y = float(input("What is/was the sales tax?")) 
z = float(input("What percentage tip would you like to leave?")) 

print ("Original Food Charge: ${}" 
.format(x)) 
print ("Sales Tax: ${}" 
.format((y/100)*x)) 
print ("Tip: ${}" 
.format(x*(z/100))) 
print ("Total Charge For Food: ${}" 
.format(x+((y/100)*x)+((z/100)*x))) 
+0

thx fixed not working though:/ line 10,in Syntax Error:.format(x * 1))):, line 1017 – user1693293

+0

'.format(x * 1)))'?你在哪裏得到這條線,你沒有在你的問題中提供這個?什麼是1017行? –

+0

我不知道!我應該替換.format(x)))哪個不起作用? – user1693293

4

你錯過了第三次印刷後尾架:.format(x*(z/100)))

這裏是什麼似乎是一個工作版本之後,我固定支架:

x = float(input("What is/was the cost of the meal?")) 
y = float(input("What is/was the sales tax?")) 
z = float(input("What percentage tip would you like to leave?")) 

print("Original Food Charge: ${}".format(x)) 
print("Sales Tax: ${}".format((y/100)*x)) 
print("Tip: ${}".format(x*(z/100))) 
print("Total Charge For Food: ${}".format(x+((y/100)*x)+((z/100)*x))) 

也有不需要換行,如果線寬小於79

+0

我已經修復了你推薦的東西,現在仍然在:第10行,在 語法錯誤:.format(x))):第1015行...........建議? – user1693293

+0

@ user1693293我相信我固定了括號,所以我現在發佈了這個代碼 – jamylak

+0

哦,哇,你是怎麼做到的......!如此簡單和少,它的工作原理! – user1693293

2

你錯過了前行密切括號:

.format(x*(z/100)) 
+0

好的,我做了改變,仍然沒有運行任何明顯的建議嗎? – user1693293