+-
Python:为什么它不接受01或02或03的输入?
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

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

最佳答案
在python2.x中,0是八进制数字的前缀…

>>> 010
8

所以,有些数字无效……例如08(因为那超出了八进制数的范围).

如果你改变代码使用int(raw_input(‘…’)),它应该工作,因为int总是假定为10,除非你另有说明.

>>> int('08')
8
点击查看更多相关文章

转载注明原文:Python:为什么它不接受01或02或03的输入? - 乐贴网