Python:为什么它不接受01或02或03的输入?

Edu*_*les 3 python

print "What is your name?",
name = len(raw_input())
print name
print "How old are you?",
age = int(input())
print "What month were you born in? ",
month = int(input())
if (month>12) or (0>month):
    print "That does not exist"
else:
    all = (name+age+month)
    print "Your name length plus your age plus",
    print "the month you were born is equal to:", 
    print all
Run Code Online (Sandbox Code Playgroud)

如果你运行代码它可以工作,但是当提示输入一个月号时,如果你输入8它可以工作,但如果你输入08则不然.有人可以告诉我为什么.我使用的是Python 2.7

mgi*_*son 6

在python2.x中,0是八进制数的前缀...

>>> 010
8
Run Code Online (Sandbox Code Playgroud)

因此,某些数字将无效......例如08(因为它超出了八进制数的范围).

如果您更改要使用的代码int(raw_input('...')),它应该有效,因为int除非您另有说明,否则始终假定为10.

>>> int('08')
8
Run Code Online (Sandbox Code Playgroud)