来个Python小程序
#输入年月日确定这个日期是一年中的第多少天
# -*- coding: UTF-8 -*-y=int(raw_input("请输入年:"))m=int(raw_input("请输入月份:"))d=int(raw_input("请输入日期:"))a=(0,31,28,31,30,31,30,31,31,30,31,30,31)if m>12: raise ValueError("输入月份错误")if m in(1,3,5,7,8,10,12): if d>31: raise ValueError("输入日期错误")if m==2: if d>29: raise ValueError("输入日期错误")s=0s=sum(a[:m])+dif (y%4==0 and y%100!=0)or(y%400==0): print("闰年") if m>2: s=s+1print(s)顺便来个小总结:
常见的Python异常类型