Game of Chance - EOF error when trying to take input

I am doing this project:
https://www.codecademy.com/practice/projects/games-of-chance

I am trying to take user input:
user_guess = input("Heads or Tails? ")

but it is throwing an error:

Traceback (most recent call last):
  File "script.py", line 20, in <module>
    heads_or_tails(10,100)
  File "script.py", line 9, in heads_or_tails
    user_guess = input("Heads or Tails? ")
EOFError: EOF when reading a line

Here is my full code:

import random

money = 100

#Write your game of chance functions here

def heads_or_tails(bet,money):

  user_guess = input("Heads or Tails? ")
  result = random.randint(1,2)
  if result == 1:
    print("The coin flips... it lands on Heads!")
    if user_guess == result:
      print("You guessed correctly, you now have " + str(money))
  if result == 2:
    print("The coin flips... it lands on Tails!")
    if user_guess == result:
      print("You guessed correctly, you now have " + str(money))

heads_or_tails(10,100)



#Call your game of chance functions here

I’ve tried to isolate the problem yet I still get an EOF error.

My guess is it’s something to do with indentation or white space. I copied your code as is and just redid all the indentation and it worked fine for me. So, try doing that and see if it works.

1 Like

Hello @smartghuru. Have you tried it on an external compiler? Often there is nothing wrong with the code, it is just the CC learning environment doesn’t like input from the terminal (as I suppose a long wait could create problems in the server).

1 Like

I think this is the most likely explanation. :slight_smile:

Not all of the lessons/projects have an interactive terminal, so where a learner tries to use input() in an environment where there’s no terminal to get the input they see this error instead.

1 Like

This is not your error: If you check the hint – which most of us don’t like to do unless absolutely necessary, you’ll see that the intent is not for an interactive input but rather for a randomized guess or a programmer-created guess. I opened a bug report since this is a common issue among learners – we want to take the initiative to make it interactive, but the interface doesn’t seem to be designed to accept that approach.