gpt4 book ai didi

Python CMD 语法错误

转载 作者:太空宇宙 更新时间:2023-11-04 09:41:11 26 4
gpt4 key购买 nike

在用 Python 编写代码时,我在 CMD 中遇到了这个错误

Project11.py", line 5
if Select == 1
^
SyntaxError: invalid syntax

这是我的完整程序

print("Canadian to USD")

Select = input("Press 1 for Canadian to USD or 2 for USD to Canadian ")

if Select == 1
Canadian1 = input("Canadian ")

USD1 = int(Canadian1) * 0.63674
print("{0}$ = ${1}".format(Canadian1, USD1))

if Select == 2
USD2 = input("USD ")

Canadian2 = int(USD2) * 1.5704
print("${0}={1}$".format(USD2, Canadian2))

有人可以纠正错误或帮助我吗?谢谢:)

最佳答案

您需要在 if Select == "1"if Select == "2" 之后加上引号和冒号。

所以你的代码应该是这样的:

print("Canadian to USD")

Select = input("Press 1 for Canadian to USD or 2 for USD to Canadian ")

if Select == "1":
Canadian1 = input("Canadian ")

USD1 = int(Canadian1) * 0.63674
print("{0}$ = ${1}".format(Canadian1, USD1))

if Select == "2":
USD2 = input("USD ")

Canadian2 = int(USD2) * 1.5704
print("${0}={1}$".format(USD2, Canadian2))

关于Python CMD 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51639219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com