python‘零基础’005课《判定年份》
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 + '不是闰年!')
程序一次只能输入一次年份,该怎么让它能够重复输入呢? 6点多来看帖子 还有人发帖求助 够努力啊
while True:
temp = input('请输入一个年份(退出程序直接"回车"):')
if not temp:
break
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 + '不是闰年!') 把循环加在输入前面就可以了 yjsx86 发表于 2017-12-10 06:35
6点多来看帖子 还有人发帖求助 够努力啊
谢谢您,新人入门,找不到方向。多谢您能回答我的问题。那个最佳答案点错的,第一次不会整,请见谅。
页:
[1]