|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
temp = input('请输入一个年份:')
while not temp.isdigit():
print('抱歉,输入有误请重新输入:')
temp = input()
year = int(temp)
a = year/4
b = year/100
c = year/400
if a.isdigit() and not b.isdigit():
print(year + '是闰年')
else:
if c.isdigit():
print(year + '是闰年')
else:
print(year + '不是闰年')
会报错
line 9, in <module>
if a.isdigit() and not b.isdigit():
AttributeError: 'float' object has no attribute 'isdigit'
请问如何解决
isdigit() 使用有误。不建议你用这种方法。可以使用 % 运算符取余:
- temp = input('请输入一个年份:')
- while not temp.isdigit():
- print('抱歉,输入有误请重新输入:')
- temp = input()
- year = int(temp)
- if year % 4 == 0 and year % 100 != 0:
- print(year, "是闰年!")
- else:
- if year % 400 == 0:
- print(year, "是闰年!")
- else:
- print(year, "不是闰年!")
复制代码
|
|