所以我在写程序,但是终端给我语法错误,而其他网站给我EOF错误。同样,如果我输入一个字符串,即使我在代码中放入了ValueError,它也会给我一个错误。我该如何解决。
while True:
try:
a = (input("Enter 15 numbers: ").split())
a = [int(i) for i in a]
b = sorted(a)
c = False
except ValueError:
print("Please enter a number.")
continue
if len(b) > 15 or len(b) < 15:
print("Please enter exactly 15 numbers")
else:
c = True
break
if c == True:
print("Hello")
else:
bob = 1
print("done")
EOF错误:
$python main.py
Enter 15 numbers: Traceback (most recent call last):
File "main.py", line 3, in <module>
a = input("Enter 15 numbers: ").split()
EOFError: EOF when reading a line
语法错误:
a = (input("Enter 15 numbers: ").split())
File "<string>", line 1
1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
^
SyntaxError: invalid syntax
字符串错误:
File "inp.py", line 3, in <module>
a = (input("Enter 15 numbers: ").split())
File "<string>", line 1, in <module>
NameError: name 'd' is not defined