|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 yjptx121 于 2019-12-28 15:13 编辑
print('----------------第五课,判断是否为闰年--------------')
times = 10
print('总共有'+str(times)+'次机会')
while times:
temp = input('请输入一个年份以查询是否为闰年:')
while not temp.isdigit():
temp = input('输入有误,请重新输入:')
year = int(temp)
times = times-1
i = year/4
j = year/100
k = year/400
if (k) == int(k):
print(temp+'年是闰年')
if times>0:
print('剩余'+str(times)+'次机会,请再次输入:')
else:
if (i) == int(i) and (j) != int(j):
print(temp+'年是闰年')
else:
print(temp+'年不是闰年')
if times>0:
print('剩余'+str(times)+'次机会,请再次输入:')
print('查询结束')
有个问题,就是if后面一定要加else吗,貌似不加也可以运行 |
|