鱼C论坛

 找回密码
 立即注册
查看: 2201|回复: 5

[已解决]005作业,闰年这个如何让它循环起来?

[复制链接]
发表于 2020-3-4 20:37:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
查一次就退出了,如何让它循环查?
  1. temp = input('请输入一个年份:')
  2. while not temp.isdigit():
  3.     temp = input("抱歉,您的输入有误,请输入一个整数:")

  4. year = int(temp)
  5. if year/400 == int(year/400):
  6.     print(temp + ' 是闰年!')
  7. else:
  8.     if (year/4 == int(year/4)) and (year/100 != int(year/100)):
  9.         print(temp + ' 是闰年!')
  10.     else:
  11.         print(temp + ' 不是闰年!')
复制代码
最佳答案
2020-3-4 20:38:37
直接套上循环语句即可
  1. while True:
  2.     temp = input('请输入一个年份:')
  3.     while not temp.isdigit():
  4.         temp = input("抱歉,您的输入有误,请输入一个整数:")
  5.      
  6.     year = int(temp)
  7.     if year/400 == int(year/400):
  8.         print(temp + ' 是闰年!')
  9.     else:
  10.         if (year/4 == int(year/4)) and (year/100 != int(year/100)):
  11.             print(temp + ' 是闰年!')
  12.         else:
  13.             print(temp + ' 不是闰年!')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-3-4 20:38:37 | 显示全部楼层    本楼为最佳答案   
直接套上循环语句即可
  1. while True:
  2.     temp = input('请输入一个年份:')
  3.     while not temp.isdigit():
  4.         temp = input("抱歉,您的输入有误,请输入一个整数:")
  5.      
  6.     year = int(temp)
  7.     if year/400 == int(year/400):
  8.         print(temp + ' 是闰年!')
  9.     else:
  10.         if (year/4 == int(year/4)) and (year/100 != int(year/100)):
  11.             print(temp + ' 是闰年!')
  12.         else:
  13.             print(temp + ' 不是闰年!')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-4 20:39:27 | 显示全部楼层
  1. while True:
  2.     temp = input('请输入一个年份:')
  3.     while not temp.isdigit():
  4.         temp = input("抱歉,您的输入有误,请输入一个整数:")
  5.      
  6.     year = int(temp)
  7.     if year/400 == int(year/400):
  8.         print(temp + ' 是闰年!')
  9.     else:
  10.         if (year/4 == int(year/4)) and (year/100 != int(year/100)):
  11.             print(temp + ' 是闰年!')
  12.         else:
  13.             print(temp + ' 不是闰年!')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-4 20:39:34 From FishC Mobile | 显示全部楼层

  1. while 1:
  2.     temp = input('请输入一个年份:')
  3.     while not temp.isdigit():
  4.     temp = input("抱歉,您的输入有误,请输入一个整数:")

  5.     year = int(temp)
  6.     if year/400 == int(year/400):
  7.         print(temp + ' 是闰年!')
  8.     else:
  9.         if (year/4 == int(year/4)) and (year/100 != int(year/100)):
  10.             print(temp + ' 是闰年!')
  11.         else:
  12.             print(temp + ' 不是闰年!')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-4 20:41:16 | 显示全部楼层
  1. while True:
  2.     temp = input('请输入一个年份:')
  3.     if temp = 'Q': # 退出
  4.         break
  5.     while not temp.isdigit():
  6.         temp = input("抱歉,您的输入有误,请输入一个整数:")

  7.     year = int(temp)
  8.     if year/400 == int(year/400):
  9.         print(temp + ' 是闰年!')
  10.     else:
  11.         if (year/4 == int(year/4)) and (year/100 != int(year/100)):
  12.             print(temp + ' 是闰年!')
  13.         else:
  14.             print(temp + ' 不是闰年!')
  15. print("BYEBYE!")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-4 20:45:11 | 显示全部楼层
10次版
  1. print ("""-----A GOOD GAME-----""")
  2. count = 10
  3. while count > 0:
  4.     temp = input("请输入一个年份:")
  5.     count = count - 1
  6.     while not temp.isdigit()and count > 0:
  7.         temp = input ("不是整数,请重新输入一个年份:")
  8.         count = count - 1
  9.     if not temp.isdigit():
  10.         print ("没机会了...")
  11.     else:
  12.         guess = int(temp)
  13.         if guess/4 == int(guess/4) and guess/100 != int(guess/100):
  14.             print("这是闰年!")
  15.         else:
  16.             if guess/400 == int(guess/400):
  17.                 print("这是闰年!")
  18.             else:
  19.                 print ("这不是闰年!")
  20. print ("""-----游戏结束-----""")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-7-5 05:56

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表