|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
print('-----判断是否为闰年-----')
temp = input('请输入一个年份:')
cishu = 0
while (temp.isdigit() != 1) and (cishu < 3):
print('输入不正确,',end="")
temp = input('请输入一个整数:')
else:
nian = int(temp)
guess = nian/4
hahaha = nian/100
while not isinstance(guess,int) and cishu <3:
print(nian and ('年不是闰年'))
else:
if hahaha.isdigit() == 1:
print(nian and ('年不是闰年'))
else:
print(nian and ('年是闰年'))
temp = input('请继续测试:')
nian = int(temp)
cishu = cishu + 1
print('次数用完,游戏结束!谢谢!')
----------错误:一直重复测试----------
本帖最后由 jackz007 于 2022-7-25 01:20 编辑
判断整除用取余运算(运算符 :%),如果被除数可以被除数整除,则余数为 0,否则,不为 0。
- print('-----判断是否为闰年-----')
- cishu = 0
- while cishu < 3:
- while True:
- temp = input('请输入一个年份:')
- if temp . isdigit():
- break
- else:
- print('输入的不是整数')
- nian = int(temp)
- if (nian % 4 == 0 and nian % 100) or nian % 400 == 0:
- print(nian , '年是闰年')
- else:
- print(nian , '年不是闰年')
- cishu += 1
- else:
- print('次数用完,游戏结束!谢谢!')
复制代码
|
|