1.输入年、月,输出本月有多少天。合理选择分支语句完成设计任务。
输入样例1:2004 2
输出结果1:本月29天
输入样例2:2010 4
输出结果2:本月30天
D,M = map(int,input().split())
a = int(D) % 4
b = int(D) % 100
c = int(D) % 400
if ( a==0 and b !=0 and M==2) or (c==0 and M==2):
print('本月29天' )
elif (M==2):
print('本月28天')
elif (M==1 or M==3 or M==5 or M==7 or M==8 or M==10 or M==12):
print('本月有31天' )
else:
print('本月有30天')
2.用 if 判断输入的值是否为空?如果为空,报错Error。
a = input('val:')
if not a:
print('Error')
else:
print('不为空')