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’)

上一篇:Python 基础 -- if 语句


下一篇:执行循环体