y学习吧! 发表于 2022-6-20 19:37:21

为什么显示TypeError: not all arguments converted during strin...

year = input('请输入一个年份:')

while not year.isdigit():
    year = input("抱歉,您的输入有误,请输入一个整数:")
int(year)
if year%400==0:
    print("是闰年")
else:
    if year%4==0 and year%100!=0:
      print("是闰年")
    else:
      print("不是闰年")

ENHEN 发表于 2022-6-20 20:03:41

year = input('请输入一个年份:')

while not year.isdigit():
    year = input("抱歉,您的输入有误,请输入一个整数:")
year = int(year)
if year%400==0:
    print("是闰年")
else:
    if year%4==0 and year%100!=0:
      print("是闰年")
    else:
      print("不是闰年")https://cdn.jsdelivr.net/gh/master-of-forums/master-of-forums/public/images/patch.gif

ENHEN 发表于 2022-6-20 20:13:26

while not year.isdigit():这里只是检测是不是全是数字
int(year)这里转换为整型却没有赋值,没办法使用,year还是一个字符串https://cdn.jsdelivr.net/gh/master-of-forums/master-of-forums/public/images/patch.gif
页: [1]
查看完整版本: 为什么显示TypeError: not all arguments converted during strin...