Python 如何检查一个月是否有31天

Python 如何检查一个月是否有31天,python,Python,下面是计算给定日期是否无效的代码。我怎么说: (if 31==天,月份不是1,3,5,7,8,10或12)或(有32个我在网上找到了一些Python代码来验证日期(如果这真的是你的目标的话)。下面是代码的副本 (请注意,它不使用日历模块,顺便说一句。) year=int(输入(“输入年份:”) 月份=整数(输入(“输入月份:”) 日期=整数(输入(“输入日期:”) #获取给定月份中某一天的最大值 如果月份==1或月份==3或月份==5或月份==7或月份==8或月份==10或月份==12: 最大日

下面是计算给定日期是否无效的代码。我怎么说:


if 31==天,月份不是1,3,5,7,8,10或12)或(有32个我在网上找到了一些Python代码来验证日期(如果这真的是你的目标的话)。下面是代码的副本

(请注意,它不使用
日历
模块,顺便说一句。)

year=int(输入(“输入年份:”)
月份=整数(输入(“输入月份:”)
日期=整数(输入(“输入日期:”)
#获取给定月份中某一天的最大值
如果月份==1或月份==3或月份==5或月份==7或月份==8或月份==10或月份==12:
最大日值=31
如果月份==4或月份==6或月份==9或月份==11:
最大日值=30
如果年份%4==0,年份%100!=0或年份%400==0:
最大日值=29
其他:
最大日值=28
如果月份<1或月份>12:
打印(“日期无效”)
elif日<1或日>最大日值:
打印(“日期无效”)
其他:
打印(“有效日期”)

如果startDayQuery==31且startMonthQuery不在[1,3,5,7,8,10,12]或startDayQuery中,您的意思是这样的吗
startMonthQuery = int(input(" What month are you starting in?\n>"))
startDayQuery = int(input(" What day are you starting on?\n>"))

if startMonthQuery <= 0:
  print("That is not a valid month, please don't put zero or a negative number.")
elif startMonthQuery >= 13:
  print("That is not a valid month, please do not put a thirteen or higher.")

if startDayQuery <= 0:
  print("That is not a valid day, please do not put a zero or negatuve number.")
elif (startDayQuery >= 32)
  print("That is not a valid day, it either doesn't have 31 days or you have entered a number far too high.")
year = int(input("Enter year: "))
month = int(input("Enter month: "))
day = int(input("Enter day: "))

# Get Max value for a day in given month
if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:
    max_day_value = 31
elif month == 4 or month == 6 or month == 9 or month == 11:
    max_day_value = 30
elif year % 4 == 0 and year % 100 != 0 or year % 400 == 0:
    max_day_value = 29
else:
    max_day_value = 28

if month < 1 or month > 12:
    print("Date is invalid.")
elif day < 1 or day > max_day_value:
    print("Date is invalid.")
else:
    print("Valid Date")