【发布时间】:2016-02-25 20:40:21
【问题描述】:
#setBirthday sets their Birthday to a date
def setBirthday(self):
while True:
try:
day = int(raw_input('Please enter the date of the month (1-31) you were born on here ->'))
if day <= 0 or day >= 32:
print "better try again..."
except ValueError:
continue
else:
break
month = int(raw_input('Please enter the month of the year (1-12) you were born on here ->'))
if month <= 0 or day >= 13:
print "better try again..."
except ValueError:
continue
else:
break
year = int(raw_input('Please enter the year you were born (19xx or 20xx) here ->'))
self.birthday = datetime(year, month, day)
print str(varPerson.getName()) + " you were born on " + str(month) + "/" + str(day) + "/" + str(year)
缩进错误就在 varPerson 的最后 3 行之上。我已经尝试并尝试让这个场景与异常一起工作,以便能够拥有一个平稳运行的脚本,如果值不合适,可以进行额外的尝试。建议?我一直在使用此链接寻求帮助:
【问题讨论】:
-
这是在windows中运行的..
-
@Obj3ctiv3_C_88:原谅?
if __name__ == '__main__':在所有平台上都是可选的。 -
你为什么要把一堆方法定义放在一个循环里?还有
try?您是否预计定义会出错并需要重做? -
@Obj3ctiv3_C_88:不,不是。如果我错了,请告诉我记录在哪里。