yjptx121 发表于 2019-12-28 15:12:06

鱼C第五课作业

本帖最后由 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吗,貌似不加也可以运行

czfasaoyou 发表于 2019-12-30 10:49:34

总感觉哪里不对
页: [1]
查看完整版本: 鱼C第五课作业