[Python] Is the CS50x Python grader bugged for the "Outdated" project or is there an error in...

Discussão em 'Python' iniciado por Stack, Setembro 3, 2025.

  1. Stack

    Stack Membro Participativo

    This is my first post on stackoverflow so I apologize if this is the wrong place to ask this question.

    I've been trying to teach myself Python using the free CS50x course and have been stuck on the Outdated project for over 3 hours. The project is to write a program that converts date formats. When I test the code manually, I get the expected result. However, when I use the auto-grader, it says my code isn't meeting the criteria of turning dates with format mm-dd-yyyy and Month d, yyyy to the format yyyy-mm-dd. Below is a link to the project description. Any help would be appreciated!

    Project:https://cs50.harvard.edu/python/psets/3/outdated/

    Below is the code I wrote and the answers that the auto-grader is marking as incorrect.

    Code:

    def main():
    months = [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
    ]
    while True:
    try:
    date = input("Date: ").strip()
    month, day, year = date.split("/")
    month, day, year = int(month), int(day), int(year)
    if not 1 <= month <= 12:
    pass
    elif not 1 <= day <= 31:
    pass
    elif not 1 <= year <= 9999:
    pass
    else:
    value = (f"{year:04}-{month:02}-{day:02}")
    print(value)
    break
    except ValueError:
    if date.find(", ") == -1:
    pass
    else:
    date2 = date.split(" ")
    month, day, year = date2
    day = day.replace(",","")
    month = months.index(month) + 1
    month, day, year = int(month), int(day), int(year)
    if not 1 <= month <= 12:
    pass
    elif not 1 <= day <= 31:
    pass
    elif not 1 <= year <= 9999:
    pass
    else:
    value = (f"{year:04}-{month:02}-{day:02}")
    print(value)
    break





    main()



    Results of the auto-grader:

    :( input of 9/8/1636 outputs 1636-09-08 Did not find "1636-09-08" in "1636-90-80Date: "

    :( input of September 8, 1636 outputs 1636-09-08 Did not find "1636-09-08" in "1636-09-80Date: "

    :( input of 10/9/1701 outputs 1701-10-09 Did not find "1701-10-09" in "1701-10-90Date: "

    :( input of October 9, 1701 outputs 1701-10-09 Did not find "1701-10-09" in "1701-10-90Date: "

    :( input of " 9/8/1636 " outputs 1636-09-08 Did not find "1636-09-08" in "Date: "

    Continue reading...

Compartilhe esta Página