py教程第5讲:解决闰年问题----input()的返回值始终是字符串

temp = input('请输入年份:')

while not isinstance(temp, int):
  temp = input('抱歉,您的输入有误,请输入年份:')

year = int(temp)
if year % 400 == 0:
  print('%d是闰年!'%(year))
else:
if year % 4 == 0 and year % 100 != 0:
  print('%d是闰年!' %(year))
else:
  print('%d不是闰年!' %(year))

 

 

所以更改后的代码如下(只修改while语句部分):

while not temp.isdigit():
  temp = input('抱歉,您的输入有误,请输入年份:')

 

 

Built-in Funtions BIF:内置函数

 

posted @ 2016-11-17 11:02  月光边境Eric  阅读(391)  评论(0编辑  收藏  举报