Computer Science, asked by unknown23dfsd7, 11 months ago

Carefully look at the following code and its execution on python shell.
Why is the last assignment giving error?
>>> a = 0o12
>>> print(a)
10
>>> b=0o13
>>> c=0o78
File “ c = 0o78
^
SyntaxError: invalid syntax

Answers

Answered by fiercespartan
17

When we use 0o or 0O, we ask python to convert the octal numbers to decimal numbers and octal numbers go only until 7, it an be 77777777777 and never ending but none of the digits in octal numbers can not be a 8.

When we convert 12 to decimal number, we get 10 because it meets the criteria to be converted to normal decimal numbers.

13 could be converted to normal decimal numbers too but,

78 can not be converted to decimal numbers because there is 8 in the number and this is not acceptable. When we use '0o', it has to be an octal number, anything else, there would be an error.

Similar questions