【发布时间】:2022-01-22 11:55:02
【问题描述】:
我正在编写一个 python 代码,我可以将许多数字添加到一个集合中,然后打印它。我不知道为什么它会返回错误。这是我的代码:
ask = int(input('How many numbers you want to add in a set?'))
sett = set()
while ask:
a = int(input('Enter the number:')
sett.add(a)
ask = ask-1
if ask == 0:
print(sett)
break
但是它返回了这个错误:
文件“Untitled5.py”,第 5 行
sett.add(a)
^
SyntaxError: 无效语法
所以任何人都可以找到错误的原因吗?这个问题可能很容易回答,但请回答。
【问题讨论】:
-
上一行缺少右括号。投票结束是一个琐碎的错字。
-
你忘了关闭括号:
int(input('Enter the number:'))
标签: python