I am doing the CS50P and am doing the outdated exercise. This is the exercise: https://cs50.harvard.edu/python/2022/psets/3/outdated/
My code does everything perfectly, except it outputs single digit dates with the zero behind the number.
Here is my code:
month = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
def get_date():
while True:
date = input("Date: ").strip().title().strip(",").replace(" ","/")
try:
# ask user for date in month,day,year
m,d,y = date.split("/")
# the input is valid if not prompt again
# check if day is upto 31 char and year is four char
if len(y) == 4 and int(d) >= 1 and int(d) <= 31:
# check if the first item is a letter or number
if m.isdigit() and int(m) >=1 and int(m) <= 12:
print(f"{y}-{m:02}-{d:02}")
# if it is a letter check if it corrospends to a month in the list
else:
if m.isalpha():
for char in month:
if m == char:
m = month.index(m) + 1
print(f"{y}-{m:02}-{d:02}")
except:
pass
get_date()
Why is it doing this.