2015-04-04 92 views
0

所以我試圖編程的東西,並有一些奇怪的事情,當試圖運行我的代碼我得到的第3行語法錯誤,但是當我只運行特定的代碼行一切正常。這怎麼可能?它是用python寫的(如果有的話)代碼中的語法錯誤,但不是在代碼行

p = float(input("What is the initial investment? ")) 
r = float(input("What is the nominal interest rate as a decimal? ") 
n = float(input("How many times a year will the interest be compounded?  ")) 
t = float(input("How many years will the interest be compounded")) 

a = p * (1 + r/n) ** (n*t) 

print "The final amount after %f years is %f" %t %a 
+1

問題出在你的第二行。關閉括號。 – Selcuk 2015-04-04 20:41:16

+0

實際的語法錯誤在第2行 – 2015-04-04 20:42:15

回答

1

您在第2行丟失了一個右括號。正確,並且錯誤應該消失。

#Instead of 
r = float(input("What is the nominal interest rate as a decimal? ") 
#Do this 
r = float(input("What is the nominal interest rate as a decimal? ")) 
#This guy is missing - - - - - - - - - - - - - - - - - - - - - - - -^
2

試試這個,(在2nd線錯過brackets)。

r = float(input("What is the nominal interest rate as a decimal? "))