Python Forum
Error in code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Error in code (/thread-17221.html)



Error in code - iMedia - Apr-02-2019

This one working before. I am trying to figure out how to make it on a enter of a int a msg is played.

CODE:

import time #Imports the time function

#Welcome Message
print('*-*-*-*-*-*-**-*-*-*-*-*-**-*-*-*-*-*-**-*-*-*-*-*-* \n    - (Welcome to the Hotel Selection Menu) - \n*-*-*-*-*-*-**-*-*-*-*-*-**-*-*-*-*-*-**-*-*-*-*-*-* \n\nEnter one of the numbers below:\n\n> 1 add a guest entry\n> 2 view guest information\n> 3 remove guest entry\n> 4 generate new key code\n> 5 exit this program\n\n*-*-*-*-*-*-**-*-*-*-*-*-**-*-*-*-*-*-**-*-*-*-*-*-*')



#Making the functions work
while True:
    char = input()
 
    if (char == "1"):
        print("Guest Entry Add")
        time.sleep(1)
 
    if (char == "2"):
        print("View Guest Info")
        time.sleep(1)
 
    if (char == "3"):
        print("Remove Guest Entry")
        time.sleep(1)
 
    if (char == "4"):
        print("Generate new code")
        time.sleep(1)
 
    if (char == "5"):
        print("Exiting the program...")
        time.sleep(1)
        time.sleep(3)
        exit(0)
This was working at school however, I am now getting the error:

Error:
Traceback (most recent call last): File "C:/Users/<MY NAME>/Desktop/work.py", line 10, in <module> char = input() File "<string>", line 0 ^ SyntaxError: unexpected EOF while parsing
Any suggestions how to fix?


Sorry if this is a easy fix but I am new to python :)


RE: Error in code - ichabod801 - Apr-02-2019

You are running Python 3.x code in Python 2.x. In previous versions of Python, the input function tried to evaluate what was entered as if it was Python code. So if you run the program and enter nothing, it gives an error, because there is no code to evaluate. Note that if you enter a number, it will evaluate that into an integer. However, all of your conditionals are based on strings, so none of them will trigger.

How you fix this is going to depend on your system. You may not have a newer version of Python installed at home. Does using 'python3' instead of 'python' work? What OS are you running?


RE: Error in code - iMedia - Apr-02-2019

(Apr-02-2019, 08:43 PM)ichabod801 Wrote: You are running Python 3.x code in Python 2.x. In previous versions of Python, the input function tried to evaluate what was entered as if it was Python code. So if you run the program and enter nothing, it gives an error, because there is no code to evaluate. Note that if you enter a number, it will evaluate that into an integer. However, all of your conditionals are based on strings, so none of them will trigger.

How you fix this is going to depend on your system. You may not have a newer version of Python installed at home. Does using 'python3' instead of 'python' work? What OS are you running?

I am running windows 10 personal on a MSI notebook and python version 2.7


RE: Error in code - ichabod801 - Apr-02-2019

Did python3 work to run the program on the command line? If not, you need to install the latest version of Python on your computer.


RE: Error in code - iMedia - Apr-02-2019

(Apr-02-2019, 10:07 PM)ichabod801 Wrote: Did python3 work to run the program on the command line? If not, you need to install the latest version of Python on your computer.
I installed python 3 and it fixed it thanks!