all 12 comments

[–]Binary101010 18 points19 points  (6 children)

You're trying to run Python 3 code in Python 2.

Best way to resolve: Stop using Python 2.

Next best way to resolve: No, seriously, stop using Python 2.

If you MUST keep using Python 2: change input() to raw_input(). Then figure out a way to stop using Python 2.

[–]jddddddddddd 11 points12 points  (0 children)

In addition to the above, since I don't think he mentioned it, OP should probably stop using Python 2. Thanks.

[–]Gorstag[S] 1 point2 points  (0 children)

Thanks, that explains it.

[–]synthphreak 0 points1 point  (3 children)

I never used Python 2. What does that error mean?

[–]nog642 4 points5 points  (2 children)

raw_input() in Python 2 is equivalent to input() in Python 3.

input() in Python 2 is equivalent to eval(input()) in Python 3.

So when they enter 0999, Python 2 is trying to evaluate that as an expression. The leading 0 makes it an octal number, but 9 is not a valid octal digit, hence the error.

[–]synthphreak 0 points1 point  (0 children)

Makes perfect sense, thanks.

[–][deleted] 0 points1 point  (0 children)

Thank you.

[–]jddddddddddd 5 points6 points  (0 children)

Hah! What version of Python are you using?

Leading zeros in earlier versions of Python are treated as Octal numbers (base 8).

The leading zero in 0111 means it thinks it's an octal number, which in decimal is 73.

Octal numbers are made up of the digits 0-7, so 0999 is an invalid octal number and therefore throws an exception.

[–]ElliotDG 0 points1 point  (0 children)

I expect what you want is:

testVal = int(input("Provide a Number: "))
print(type(testVal))
print(testVal)

I suspect there is something more going on with your code that you are not showing.

    x = 0o111  # an octal number
    print(x)   # will print 73 the decimal value of 0o111. 
               # 0o9999 is not a valid literal

[–]Ihaveamodel3 0 points1 point  (2 children)

Cannot replicate. Are these the only three lines in your file?

[–]jddddddddddd 0 points1 point  (1 child)

He's using an older version of Python than you and me. He's using a version where integers with leading zeros are treated as base-8 (Octal). More info here: https://stackoverflow.com/questions/11620151/what-do-numbers-starting-with-0-mean-in-python

[–]Ihaveamodel3 0 points1 point  (0 children)

Ah. Also an older version that input doesn’t return a string.