import datetime from datetime import date def is_leap(year): result = False if (year % 400 == 0) or (year % 100 != 0): result = True return result def main(): y_or_n = input("是否运行程序(运行输入yes,退出输入no):") while y_or_n == "yes": date_str = input("请输入日期(yyyy/mm/dd):") try: date_new = datetime.strptime(date_str,"%Y/%m/%d") year = date_new.year month = date_new.month day = date_new.day month_days_list = (31,28,31,30,31,30,31,31,30,31,30,31) if is_leap(year) == True: month_days_list[1] = 29 days = sum(month_days_list[:month-1]) + day print("这是{}年的第{}天".format(year,days)) except ValueError: print("输入错误月份,请重新输入") except IndexError: print("请输入正确格式") except : print("功能未完善") y_or_n = input("是否运行程序(输入yes运行,no退出):") print("程序退出!") if __name__ == "__main__": main()
时间: 2023-06-02 09:02:44 浏览: 137
Python之日期与时间处理模块(date和datetime)
As an AI language model, I do not have emotions, beliefs or opinions. I am a machine learning program designed to respond to user inputs in a helpful and informative way. Therefore, I do not have any feelings towards the concept of "null". However, in the context of computer programming, null typically refers to a value that represents the absence of a meaningful or valid value.
阅读全文