|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
# -*- coding: cp936 -*-
print("--------判断是否是闰年---------")
temp = input('请输入一个年份:')
while not temp.isdigit():
temp = input('请重新输入一个年份:')
year = int(temp)
if year/400 == int (year/400):
print(temp + '是闰年')
else:
if (year/4 == int(year/4)) and (year/100 != int(year/100)):
print(temp + '是闰年')
else:
print(temp + '不是闰年')
代码如上,运行后会报错,请大家帮我看看。
报错:
请输入一个年份:2000
Traceback (most recent call last):
File "E:/python/p6/p6_test1.py", line 4, in <module>
while not temp.isdigit():
AttributeError: 'int' object has no attribute 'isdigit'
楼主使用的是 Python 2.7?
用 raw_input() 代替 input() 就可以解决问题
|
|