我承认我刚刚开始使用python,但我似乎遇到了问题。我创建了这个计算器程序,当我打开它时,python窗口弹出半秒而不是消失。有人知道为什么吗?可能是语法错误或python有什么问题吗?我正在运行Windows 10和最新版本的python。我的所有代码都在下面,谢谢。
def multiply():
print("Choose two numbers to multiply by")
A = int(input("Enter A: "))
B = int(input("Enter B: "))
return A * B
def divide():
print("Choose two numbers to divide by")
A = int(input("Enter A: "))
B = int(input("Enter B: "))
return A / B
def subtract():
print("Choose two numbers to divide by")
A = int(input("Enter A"))
B = int(input("Enter B"))
return A - B
def add():
print("Choose two numbers to divide by")
A = int(input("Enter A"))
B = int(input("Enter B"))
return A + B
def squareRoot():
print("Choose what number to take the square root of")
A = int(input("Enter A"))
return A ** .5
def Square():
print ("Choose what number to square")
A = int(input("Enter A"))
return A **
Print ("1: Addition")
Print ("2: Subtract")
Print ("3: Multiply")
Print ("4: Divide")
Print ("5: Square Root")
Print ("6: Square")
Print ("7: QUIT")
while True:
Choice = int(input("Enter the corresponding number for calculation"))
if Choice == 1:
print ("Adding two numbers")
print add()
elif Choice == 2:
print("Subtracting numbers")
print subtract()
elif Choice == 3:
print("Multiplying numbers")
print multiply()
elif Choice == 4:
print("Dividing numbers")
print divide()
elif Choice == 5:
print("Taking the square root, your majesty")
print squareRoot()
elif Choice == 6:
print("Squaring your god damned number")
print squareRoot()
elif Choice == 7:
exit()
else:
Print("You didnt choose one of the options")
答案 0 :(得分:2)
Python启动正常并开始运行脚本,但Square()
中出现错误,引发了未处理的SyntaxError
异常。该错误导致脚本终止并关闭窗口。 Square()
中的return语句应为:
return A * A
不
return A **
下一个错误是您正在调用Print()
而不是print()
。您正在使用Python 3,但还有其他print
语句实际上应该调用print function ,即print()
,示例第48行
此外,还有一个错误,其中选项6调用squareRoot()
而不是Square()
。
找到所有这些错误的最佳方法是从Windows终端的命令行执行脚本。