Files
2025PY/day05/05-作业.py
2025-05-22 16:50:44 +08:00

17 lines
711 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 用户输入一个年份,判断该年份是否为闰年
# 闰年的条件:
# 输入4位数的年份如果年份能被4整除且(and)不能被100整除或(or)者能被400整除
# 条件
# 能被4整除year % 4 == 0 当前的年份和4取余数等于0,表示能够整除
# 不能被100整除year % 100 != 0 表示不能整除
# 能被400整除 year % 400 == 0
year = int(input('请输入一个4位的年份:')) # 接收用户输入一个年份(转整数)
if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: # 闰年的条件
print(f"你输入的年份是{year},它是闰年") # 满足条件
else:
print(f"你输入的年份{year},它是平年") # 不满足条件