I just completed the Problem "Outdated" in QuestionSet 3 of Harvard Python CS50p 2022 version. using Check50 v3.3.11, the automatic check function tried several scenarios and all passed with only one exception.
When the Check50 Bot inputs of "9/8/1636 " and expects outputs "1636-09-08"', my program did not give any output. When I manually checked by entering exactly the same "9/8/1636", it does return the correct output of "1636-09-08". Need to figure out why the program did not give right output for the inputs provided by Check50 bot.
# This List include Month spelled in letter/word format
month_a = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
]
def main():
while True:
try:
x = input("Date: ").title().strip()
if "/" in x: # check if user input format is mm/dd/yyyy
month, day, year = x.split("/")
if 1<= int(month) <= 12:
m = int(month)
if 1 <= int(day) <= 31:
d = int(day)
if 0 <= int(year) <= 9999:
y = int(year)
print(f"{y:04}","-",f"{m:02}","-",f"{d:02}",sep="")
break
elif "," in x: # check if user input format is mm dd, yyyy
month, day, year = x.split(" ")
if day[-1] == ",":
day = day.replace(',', '')
if 1 <= int(day) <= 31:
d = int(day)
if month in month_a:
m = month_a.index(month)+1
if 0 <= int(year) <= 9999:
y = int(year)
print(f"{y:04}","-",f"{m:02}","-",f"{d:02}",sep="")
break
except ValueError:
pass
except UnboundLocalError:
pass
main()
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744523787a4578731.html
评论列表(0条)