|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
print("········闰年查询系统········")
temp=input("请输入您想查询的年份")
a=int(temp)
b=a/4
c=a/100
d=a/400
if isinstance(d,int) == 1:
print("这是闰年")
elif (isinstance(b,int) == 1) and (isinstance(c,int) == 0):
print("这是闰年")
else:
print("这是平年")
请问各位大佬,为什么结果都是平年呢
Python 除法得到的结果都是浮点数,即使可以整除:
所以需要用求余数的方法判断:
- print("········闰年查询系统········")
- temp = int(input("请输入您想查询的年份")) # 将用户输入的数转化为整数
- if temp % 400 == 0:
- print("这是闰年")
- elif temp % 100 != 0 and temp % 4 == 0:
- print("这是闰年")
- else:
- print("这是平年")
复制代码
|
|