编程语言
首页 > 编程语言> > Python:if嵌套语句判断年份

Python:if嵌套语句判断年份

作者:互联网

写一个程序,该程序输入一个年份,根据该年份是否是建国整十周年、建党整十周年以及是否是闰年给出不同的输出

输出样例:

2:Illegal year.

1959:Legal year、Lucky year.

1931:Legal year、Good year.

2008:Legal year、Leap year.

2011:Legal year、Common year

代码:

year = int(input())
if year <= 0:
print(‘Illegal year’)
else:
print(‘Legal year’)
if year > 1949 and (year-1949) % 10 == 0: # 建国整十周年
print(‘Lucky year’)
elif year > 1921 and (year-1921) % 10 ==0: # 建党整十周年
print(‘Good year’)
elif year % 4 == 0 and (year % 100 == 0 or year % 400 == 0 ): # 闰年
print(‘Leap year’)
else:
print(‘Common year’)

标签:语句,elif,年份,Python,Legal,嵌套,十周年,year,print
来源: https://blog.csdn.net/weixin_55447224/article/details/114767845