python萌新求助,这个怎么可以循环起来?
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 + ' 不是闰年!')
这个是关于闰年的那个,这个代码如果不是闰年他就只会告诉你不是闰年就结束了,怎么才能让它不是闰年的话就要继续,知道是闰年才结束?
想了好久。总是弄不好,求大神帮助下,谢谢了。
还有就是很多行的代码怎样才能一起前面去掉一个或者多个tab?我一个一个去掉好麻烦啊~~ 在外层加一个while死循环
当是闰年的时候跳出即可
用快捷键 ctrl + [ 和 ctrl + ] 分别向左向右整体平移一个tab while True:
temp = input('请输入一个年份:')
while not temp.isdigit():
temp = input('抱歉,输入不合法,请重新输入一个年份:')
year = int(temp)
year1 = year % 4
year2 = year % 100
year3 = year % 400
ifyear1 == 0 and year2 != 0:
print('您输入的年份是闰年')
break
elif year3 == 0:
print('您输入的年份是闰年!')
break
else:
print('您输入的年份不是闰年')
页:
[1]