所以我试图编写一些东西并且有些奇怪的事情,当我尝试运行我的代码时,我在第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
答案 0 :(得分:2)
试试这个,(brackets
行中遗漏2nd
)。
r = float(input("What is the nominal interest rate as a decimal? "))
答案 1 :(得分: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 - - - - - - - - - - - - - - - - - - - - - - - - ^