I am fairly new to coding but stuck on one of these exercises;
"Write a program that accepts a date in the format DD/MM/YYYY and output whether or not the date is valid. For example 20/07/1969 is valid, but 31/09/2012 is not."
My attempt at this:
d = int(input("Enter a day"))
m = int(input("Enter a month"))
y = int(input("Enter a year"))
if d > 30 and m == [4, 6, 9, 11]:
print("This date is invalid")
elif d > 31:
print ("This date is invalid")
elif m != [1,2,3,4,5,6,7,8,9,10,11,12]:
print ("This date is invalid")
else:
print("This date is valid")
Any suggestions on how to fix this is appreciated
dateobject of thedatetimemodule. Probably not allowed, but here you also have to take leap years into account, etc. and some calendars even changed through time, making it very hard to parse it correctly without any error. For example, before 8 BC, a leap year took place every three years.