Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in code
#1
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 :)
Reply
#2
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?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(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
Reply
#4
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
(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!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020