def days_in_month(m):
for m in range (January,December):
return (month_days[0],month_days[11])
month_days= [('January'[31]), ('February'[28,29]), ('March'[31]), ('April'[30]), ('May'[31]), ('June'[30]), ('July'[31]), ('August'[31]), ('September'[30]), ('October'[31]), ('November'[30]), ('December'[31])]
day_names=['Monday' 'Tuesday' 'Wednesday' 'Thursday' 'Friday' 'Saturday' 'Sunday']
我应该使用python列表来存储每个月的名称和每个月的天数,我的程序应该接受一个参数(一个月)并返回该特定月份的设定天数。我遇到了问题 每个指定月份的天数,我都试过寻找答案 到处都没有。请帮忙。提前致谢。
答案 0 :(得分:0)
我建议使用month_days字典
def days_in_month(m):
return month_days[m]
month_days= {'January':31, 'February':[28,29] etc...}
day_names=['Monday' 'Tuesday' 'Wednesday' 'Thursday' 'Friday' 'Saturday' 'Sunday']
我不完全明白你想要回到这里。但是这段代码将返回存储在字典中的数字。
因此month('January')
将返回31