I can't seem to get passed PSET3 outdated.py. I get two errors when running the check50 command:
:( input of " 9/8/1636 " outputs 1636-09-08 expected "1636-09-08", not "1636 -09-08\n"
I don't know where the extra space is coming from nor the line break at the end.
:( input of September 8 1636 results in reprompt expected program to reject input, but it did not
I am not sure what the problem here is, other than a missing comma.
Here is my code:
def main():
months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
while True:
date = input("Date: ")
try:
m, d, y = date.split("/")
if (int(m) > 0 and int(m) < 13) and (int(d) > 0 and int(d) < 32):
break
except:
try:
alt_m, alt_d, y = date.split(" ")
for month in range(len(months)):
if alt_m == months[month]:
m = month + 1
d = alt_d.replace(",", "")
if (int(m) > 0 and int(m) < 13) and (int(d) > 0 and int(d) < 32):
break
except:
print()
pass
print(f"{y}-{int(m):02}-{int(d):02}")
main()
I looked though the forum and I also found this Youtube video, which used a similar methodology, interestingly it works in the video tutorial, but reading the comments shows that others have the same problem.