0

Issue: :( input of 9/9/1636 outputs 1636-09-08

Check50 output: bunch of errors

My code isn't the cleanest or most optimized, but I'm pretty sure it works.

def main():

    day = 4000
    months = [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
    ]
    while True:
        try:
            oldDate = (input("Date: ").strip()).strip()
            type = dateType(oldDate, months)
            if type == "numbers":
                parts = oldDate.split("/")
                year = parts[2]
                month = parts[0].zfill(2)
                day = parts[1].zfill(2)
            elif type == "name":
                for c in range(len(months)):
                    if oldDate.split()[0].title() in months[c]:
                        month = c+1
                        month = str(month).zfill(2)
                        split = oldDate.replace(",", "").split()
                        year = split[2]
                        day = split[1].zfill(2)


            if int(day) < 31:
                print(year.strip(),month.strip(),day.strip(), sep ="-", end="")
                print()

        except EOFError:
            print()
            break
        except ValueError:
            pass

def dateType(oldDate, months):
    if oldDate.split()[0].title() in months:
        return "name"
    elif isNumbers(oldDate):
        return "numbers"

def isNumbers(oldDate):
    parts = oldDate.split("/")
    for c in parts:
        for d in c:
            if d.isalpha():
                return False
    return True
main()

1 Answer 1

0

The "Actual Output" shown in check50 does not match the output required by the spec. Review the demo. The program needs to break out of the while loop once it produces output.

1
  • Thanks, I didn't realize I needed to break out. Commented Oct 26, 2023 at 0:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .