首页 > 解决方案 > 编译为 .EXE 文件“语法错误:解析时出现意外 EOF”后,简单计算器停止工作

问题描述

我是编码新手。我想了解为什么会发生这样的事情,当然我该如何解决它。

当我运行 .PY 脚本时,它工作正常。但是当我在 CMD 中运行它或将其编译为 EXE 时,它会打开或启动。我可以填写我的第一个号码。但是当我想填写运算符时,它停止工作并给我这个错误:Syntax error: Unexpected EOF while parsing.

CMD 报错截图:

CMD 中的错误截图

该文件的完整代码:

i = 1
print("------------------CALCULATOR------------------")
print("-------- Valid operators:  +, -, /, * --------")
print("----------------------------------------------")
while i <= 2:
    num1 = float(input("Enter your first number: "))
    op = input("Enter the operator: ")
    num2 = float(input("Enter your second number: "))
    if op == "+":
        print(num1 + num2)
    elif op == "-":
        print(num1 - num2)
    elif op == "/":
        print(num1 / num2)
    elif op == "*":
        print(num1 * num2)
    else:
        print("You need to enter a valid operator!")

    more_calc = input("Do you want to do another calculation?\n---> ")
    if more_calc == "yes":
        print("----------------------------------------------\nOk!")
    elif more_calc == "no":
        i += 2

input("\n----------------------------------------------\nThank you for using my Calculator!\nPress enter to exit.\n----------------------------------------------")

标签: pythonpython-3.xcompilationsyntax-erroreof

解决方案


推荐阅读