I am trying to do a simple toto history with a dictionary and function however I have this funny syntax error that keeps appearing that states "unexpected EOF while parsing" on the python shell when I try to runs it. I re-looked over and over however I cannot find the error. I used input for input of integers therefore I do not think that the problem might lie with the input or raw_input. Please help me ! Below are my codes and the error on the python shell.
options()
choice = input ("Enter your choice: ")
printwhile choice != -1:if choice == 1:print("Choice 1")for key in toto_book:print key + "\t" + "Day: " + toto_book[key][0] + '\t' + 'Winning Numbers: ' + str(toto_book[key][1] + 'Additional Number: ' + toto_book[key][2]elif choice == 2:print("Choice 2")draw = raw_input("Enter draw date(dd/mm/yy): ")if draw in toto_book:print (draw + "\t" + "Day: " + toto_book[draw][0] + "\t" + "Winning Numbers: " + str(toto_book[draw][1]) + 'Additional Number: ' + toto_book[draw][2]) else:print draw + ' cannot be found.'
There is a syntax error at the elif choice == 2:
line.
Updated
As pointed out by @cricket_007, this answer is based on the false assumption that Python 3 is being used. Actually, Python 2 is being used and the only serious problem is that the call to str
is missing a closing parenthesis.
You are using Python 3 in which print
is a function, not a statement (as it is in Python 2).
This is the line causing the problem:
print key + "\t" + "Day: " + toto_book[key][0] + '\t' + 'Winning Numbers: ' + str(toto_book[key][1] + 'Additional Number: ' + toto_book[key][2]
Add parentheses to make print
a function call, i.e. print(...)
:
print(key + "\t" + "Day: " + toto_book[key][0] + '\t' + 'Winning Numbers: ' + str(toto_book[key][1]) + 'Additional Number: ' + toto_book[key][2])
Also, the call to str()
was missing the closing parenthesis.
There is a similar problem on line 15.
Other problems:
input()
returns a string, not an integer so your if choice ==
statements will never be true. Either convert choice
to an integer
with choice = int(choice)
after the input()
, or use a string in
the if
statements, e.g. if choice == '1'
.
- The
while
loop is infinte, and unnecessary for the code shown (perhaps it is a work in progress?).