求求大佬们帮忙看下这个代码问题出在哪里
temp = input("请输入年份:")year = str(temp)
while True:
if year.isdigit == True:
break
else:
temp = input("数据有误,请重新输入:")
year = str(temp)
continue
year = int(year)
if (year&4) == 0 and (year&100) != 0:
print("是")
elif (year&400) == 0:
print("是")
else:
print("不是")
计算输入的年份是否为闰年,但是无论输入什么都是会跳到数据有误哪里,请大佬们帮忙看下问题在哪 temp = input("请输入年份:")
year = str(temp)
while True:
if year.isdigit() == True:
break
else:
temp = input("数据有误,请重新输入:")
year = str(temp)
continue
year = int(year)
if (year%4) == 0 and (year%100) != 0:
print("是")
elif (year%400) == 0:
print("是")
else:
print("不是")
%打错打成&了wuwuwu
basketmn 发表于 2021-3-11 11:41
哥问题在哪里 isdigit()少了括号,还有不是year%什么的吗
不用转换类型了,temp本身就是str类型,不过你那样写也没问题
year = input("请输入年份:")
while True:
if year.isdigit() == True:
break
else:
year = input("数据有误,请重新输入:")
continue
year = int(year)
if (year%4) == 0 and (year%100) != 0:
print("是")
elif (year%400) == 0:
print("是")
else:
print("不是") 巴巴鲁 发表于 2021-3-11 11:45
isdigit()少了括号,还有不是year%什么的吗
不用转换类型了,temp本身就是str类型,不过你那样写也没问题
...
谢谢哥 找到答案了!
页:
[1]