这有很多改变要做。首先,第一行代码应该是:
print ("Hello")
然后,raw_input() 应该变成 input()。
接下来,除了在定义函数时的第二行之外,calc() 之后不应有冒号或分号。
代码应该看起来像这样。试试看。
print ("Hello")
def calc():
x = int(input("Input first integer: "))
y = int(input("Input second integer: "))
type = str.lower(input("(A)dd, (S)ubstract, (M)ultiply, (D)ivide \n"))
if type != "a" and type != "s" and type != "m" and type != "d":
print ("Sorry, the command you entered is not valid.")
calc()
else:
if type =="a":
print ("The result is '" + str(x+y) + "'")
elif type == "s":
print ("The result is '" + str(x-y) + "'")
elif type =="m":
print ("The result is '" + str(x*y) + "'")
elif type == "d":
print ("The result is '" + str(float(x)/float(y)) + "'")
if int(input("Enter 1 if you would like to perform another calculation? \n")) == 1:
calc()
else:
exit()
calc()
希望这可以帮助。