-2

number = raw_input("Enter a number.")

def function(number): if number % 9 == 0: print 9 else: print number % 9

I get the following when trying to run it:

Enter a number.Traceback (most recent call last): File "script.py", line 1, in <module> number = raw_input("Enter a number.") EOFError: EOF when reading a line

What's up with that?

  • Using python 2 btw – Jill and Jill Apr 18 '18 at 05:12
  • Please use Python 3, if you're learning it shouldn't make any difference. That said, please provide a [mcve]. Your code as it stands could probably be shortened. BTW: I guess the problem lies in how you execute it, for some reason no input seems to be available. – Ulrich Eckhardt Apr 18 '18 at 05:18

1 Answers1

0

raw input converts your input to string. You should convert it to int in order to work with it as a number:

number = int(raw_input("Enter a number."))
  • That's true, but it's not going to cause the EOF error he's seeing. – abarnert Apr 18 '18 at 05:44
  • @abarnert, yes, you are right. I think EOF error is caused by some syntax issue before the line: `number = raw_input("Enter a number.")` – Olzhas Arystanov Apr 18 '18 at 05:49
  • It wouldn't be a syntax issue. And I doubt his code is doing anything like `sys.stdin.close()`. More likely it's something about the way he's trying to run this, although I'm not sure what would do that. – abarnert Apr 18 '18 at 05:53
  • well thats actually line one, so there it couldn't be caused by anything before it. im trying to make a code that takes in input from the user then calculates its digital root, as a sort of practice. – Jill and Jill Apr 18 '18 at 07:26
  • What do you mean by command line? Sorry, I'm only just learning about coding – Jill and Jill Apr 19 '18 at 01:15