|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码1:
temp = input('请输入一个年份:')
while not 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 + ' 不是闰年!')
代码2:
var=1
while var==1:
year=input("please input a year:")
while not year.isdigit():
year=input("please input a right year:")
myyear=int(year)
if myyear%4==0:
if myyear%100==0:
if myyear%400==0:
print("the year is leap year")
else:
print("the year is not leap year")
else:
print("the year is leap year")
else:
print("the year is not leap year")
首先我要吐槽一下楼主的缩进太不规范!时而4格时而3格时而5格!
推测楼主不明白两段代码使用的运算符
二者等价,看下面的测试,不懂欢迎追问 - >>> (a/b == int(a/b)) == (a%b == 0)
- True
复制代码
|
|