0

So I am writing a program but terminal is giving me a syntax error and some other websites are giving me EOF errors. Also if I enter a string it gives me a error even though I put a ValueError in my code. How can I fix this.

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 Error:

$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

Syntax Error:

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

String Error:

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
  • is this indentation as is on your code? it's wrong from the start – L_Church Jun 22 '18 at 14:04
  • no, I had to edit it to make it easier for me to post it on stack overflow. –  Jun 22 '18 at 14:05
  • everything after the while True: is indented 4 more spaces than seen in my code. –  Jun 22 '18 at 14:06
  • 1
    If you are getting syntax errors or name errors when using `input()`, then you are **not using Python 3**. You are using Python 2 instead. Either fix what interpreter you are using, or switch to `raw_input()`. – Martijn Pieters Jun 22 '18 at 14:10
  • Well that solves a lot. Turns out I had it downloaded but my default was 2.7. –  Jun 22 '18 at 14:52

0 Answers0