本文主要是介绍Python小练习:输入某年某月某日,判断这一天是这一年的第几天?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:输入某年某月某日,判断这一天是这一年的第几天?
def date_days():
try:year = int(input("请输入年份:"))mon = int(input("请输入年份:"))date = int(input("请输入年份:"))
except:print("输入数值类型,谢谢")
date_dict_ping = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
date_dict_run = {1: 31, 2: 29, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
sum_days = 0
if (year%4==0 and year%100!=0)or year%400==0:date_dict = date_dict_runif mon>0 and mon <13:while mon > 1:sum_days = sum_days + date_dict[mon]mon -= 1else:print("输入月份错误,请重新输入")sum_days = sum_days + dateprint("这是{}年中的第{}天".format(year, sum_days))
else:date_dict = date_dict_pingif mon > 0 and mon < 13:while mon > 1:sum_days = sum_days + date_dict[mon]mon -= 1else:print("输入月份错误,请重新输入")sum_days = sum_days + dateprint("这是{}年中的第{}天".format(year, sum_days))
date_days()
有错误的话请大家指正呀
这篇关于Python小练习:输入某年某月某日,判断这一天是这一年的第几天?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!