Python:要求用 函数 实现: 从键盘输入年份和月份,然后计算返回该年该月共有多少天。

2025年03月13日 04:44
有1个网友回答
网友(1):

# encoding: utf-8
# Python 3.6.0
def getdays():
    year=input("输入年份:")
    month=input("输入月份:")
    if year=="" or month==""or year.isdigit()==False or month.isdigit()==False:
        return "输入非法"
    m=[31,28,31,30,31,30,31,31,30,31,30,31]
    if int(year)%4==0 and int(year)%100!=0 or int(year)%400==0:
        m[1]=29
    return "{0}年{1}月有{2}天".format(year, month, m[int(month)-1])
print(getdays())