Why does this input() function return an EOF error?

Hi guys, I’m super new to all of this - I’m going through the Python3 course and at the Magic8 ball task I thought I’d try my hand and doing something it didn’t ask me to do, just to see if I could

Ironically, I couldn’t… I wanted to change the question to a user input, rather than a predefined variable using
answer = input("What would you like to ask?: ") and received an EOF error, returning to a pre defined variable makes it work again, I read up on the documentation for Input and for the life of me can’t see where I’m going wrong - I also looked up the EOF error, but the resolutions seemed more advanced for where I’m at.

I was just wondering why input() seems to work fine before this task when I was asked to enter it and what is different now?

Full code below

#import randit function to to the program for randomisation later

import random

#Standard variables for later ref

name = "Harry"

question = input("What would you like to ask?: ")

answer = ""

#Varaible to hold the call to random

random_number = random.randint(1, 9)

#test random_number output

#print(random_number)

print(name + " asks " + question)

#IF commands checked against random number generated to print a random reply from below preset

if random_number == 1:

  answer = "Yes - definitely"

elif random_number == 2:

  answer = "It is decidedly so"

elif random_number == 3:

  answer = "Without a doubt"

elif random_number == 4:

  answer = "Reply hazy, try again."

elif random_number == 5:

  answer = "Ask again later"

elif random_number == 6:

  answer = "Better not tell you now"

elif random_number == 7:

  answer = "My sources say no."

elif random_number == 8:

  answer = "Outlook not so good."

elif random_number == 9:

  answer = "Very doubtful."

else:

  answer = "Error, try again"

print("Magic 8's answer: " + answer)

Thanks in advanced :slight_smile:

This might be one of the lessons where an interactive terminal just isn’t available so you’ll get an unexpected error. If you wanted to double check you could copy your code and run it on your own PC (or several different websites for the same). At a quick glance all your syntax seems to be OK but if it fails elsewhere then by all means say so :slightly_smiling_face:

3 Likes

The EOF is encountered because there is an unclosed quoted string. Here is an example of an extra double quote that will lead to an EOF…

answer = input("What is the answer?:" ")

That’s the one, just ran it in PyCharm and it worked ok - my fault for not checking that myself! Didn’t realise that the Codecademy editor would lock out like that at certain times :slight_smile: but good to know I wasn’t doing it wrong.
Thank you!

2 Likes