python - 编译为 .EXE 文件“语法错误:解析时出现意外 EOF”后,简单计算器停止工作
问题描述
我是编码新手。我想了解为什么会发生这样的事情,当然我该如何解决它。
当我运行 .PY 脚本时,它工作正常。但是当我在 CMD 中运行它或将其编译为 EXE 时,它会打开或启动。我可以填写我的第一个号码。但是当我想填写运算符时,它停止工作并给我这个错误:Syntax error: Unexpected EOF while parsing
.
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----------------------------------------------")
解决方案
推荐阅读
- sharepoint - 如果已经存在同名文件,是否有选择如何重命名我的文件的解决方案?
- java - 将 Hashmap 上的列表添加到另一个列表时出现问题
- excel - Excel VBA中.Delete和.Clear之间的区别?
- ag-grid - 如何实现查找列值并在 ag 网格中替换为新值(如查找和替换)
- c# - 未找到 Xamarin IOS 绑定库 DLL
- angular - 如何使用gridster 2强制添加项目
- spring - 如何使用弹簧控制器和百里香叶显示进度条?
- javascript - 如何在 Blazor 项目中分离 JavaScript 文件?
- php - 如何计算 2 迟到标记为缺勤半天
- amazon-web-services - 从公司防火墙后面访问 AWS EC2