lolwut22
lolwut22

Reputation: 27

"Unexpected EOF while parsing" after a "try" statement

I'm really, really new to Python and was making a small test program.

Here is my code:

def start ():   
    print ("This is where text would be")   
    prompt_sta ()

def prompt_sta ():  
    prompt_0=raw_input("Input a Command: ")  
    try:  
        if prompt_0 == 'Okay':                             
           next_screen ()  
        else:   
            print ('Type Okay.')   
            prompt_sta ()   

when I try to run it I get the "Unexpected EOF while parsing" error.

Upvotes: 1

Views: 5784

Answers (3)

1pokepie
1pokepie

Reputation: 72

For the EOF error, you can just get rid of that try: like so

def start ():   
    print ("This is where text would be")   
    prompt_sta ()

def prompt_sta ():  
    prompt_0=raw_input("Input a Command: ")  

    if prompt_0 == 'Okay':                             
        next_screen ()  
    else:   
        print ('Type Okay.')   
        prompt_sta() 

You can also just add an except clause, as Fernando said, if you still want to use try:

Upvotes: 1

mathewguest
mathewguest

Reputation: 640

You need an except after the try. It's just a small syntax error; the eof comes from the python parser before it executes the code.

def start ():   
    print ("This is where text would be")   
    prompt_sta ()

def prompt_sta ():  
    prompt_0=raw_input("Input a Command: ")  
    try:  
        if prompt_0 == 'Okay':                             
           next_screen ()  
        else:   
            print ('Type Okay.')   
            prompt_sta ()  
    except Exception as ex:
        print (ex)

Here's the link to docs just to save a quick google: https://docs.python.org/3/tutorial/errors.html

Upvotes: 1

Fernando
Fernando

Reputation: 1450

The try needs an except clause.

Upvotes: 6

Related Questions