Saint_HUFS 发表于 2020-4-10 06:08:03

帮帮孩子吧!!!零基础的萌新

temp=input('请输入一个年份:')
times = 3
while (not temp.isdigit()) and (times > 0):
    temp = input("抱歉,您的输入有误,请输入一个整数:")
    if 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 + ' 不是闰年!')
            if times>0:
                print('try again:')
            else:
                print('times out')
    times = times - 1

----------------------------------------------------------------------------------------------------------
来个前辈帮帮我请问哪里出了问题了?

Saint_HUFS 发表于 2020-4-10 07:27:44

print('请输入一个年份:')
times = 3
while times > 0:
    temp = input()
    year = int(temp)
    if not temp.isdigit():
      temp = input("抱歉,您的输入有误,请输入一个整数:")
    else:


      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 + ' 不是闰年!')
            if times>1:
                print('try again:')
            else:
                print('times out')
      times = times - 1
-----------------------------------------------------------------
经过检查,已经解决。
页: [1]
查看完整版本: 帮帮孩子吧!!!零基础的萌新