import sys
import os
print ("Welcome to the Calculator")
def main():
a = input ("Please enter the first operand: ")
op = input ("Please enter the operation you wish to perform, +, -, *, / : ")
b = input ("Please enter the second operand: ")
a = int(a)
b = int(b)
if op == "+":
ans = (a + b)
print (ans)
elif op == "-":
ans = (a - b)
print (ans)
if op == "*":
ans = (a * b)
print (ans)
elif op == "/":
ans = (a / b)
print (ans)
again = input("Would you like to perform another calculation? Y or N?")
if again == "Y":
main()
main()
你好,不好意思问了这么多问题。
基本上,我把我的代码放在上面,并在通过双击 .py 文件执行代码时,它会从 CMD 启动它,在提示消息后:“请输入您要执行的操作,+, -, *, / :"
CMD 只是随机关闭自己。这也发生在我所有的 Python 程序中。任何想法为什么?这与我糟糕的代码有关吗?
非常感谢所有回复:)