I am trying to solve a homework task involving date validation:
"What’s the day? Design a program to take 3 inputs, one for day, one for month and one for year. Get your program to validate if this is an actual day, and, if it is, output the day of the week it is!"
I have done the first validation bit with the following code but can't do the second bit:
import datetime
print("This program will check if a date is correct and output what day of the week it was.")
day = input("Please input the day>")
month = input("Please input the month in number format>")
year = input("Please input the year, it must be after 1900>")
date_range = False
leap_year_check = 0
if (date in range(1,31)) and (month in range (1, 12)) and (year in range(1900, 2018)):
date_range = True
else:
date_range = False
if date_range == True:
leap_year_check = year % 4
if leap_year_check == 0:
if month == 2 and day in range(1, 29):
print("The date entered is a correct date")
elif month == "1" or "3" or "5" or "7" or "8" or "11" or "12" and day in range (1, 31):
print("The date entered is a correct date")
elif month == "4" or "6" or "10" or "9" and day in range (1, 30):
print("The date entered is a correct date")
elif leap_year_check != 0:
if month == 2 and day in range(1, 28):
print("The date entered is a correct date")
elif month == "1" or "3" or "5" or "7" or "8" or "11" or "12" and day in range (1, 31):
print("The date entered is a correct date")
elif month == "4" or "6" or "10" or "9" and day in range (1, 30):
print("The date entered is a correct date")
if date_range == False:
print("The date entered is incorrect")