1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Below code for CS50's Introduction to Programming with Python is not working well...

Discussão em 'Python' iniciado por Stack, Setembro 14, 2024.

  1. Stack

    Stack Membro Participativo

    month = [
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
    ]

    while True:

    try:

    date = input("Date: ").strip()

    if date.find("/"):
    if int(date.split("/")[0]) < 13 and int(date.split("/")[1]) < 32:
    date = date.split("/")
    print(f"{date[2]}-{int(date[0]):02}-{int(date[1]):02}")
    break

    elif date.find(","):
    if len(date) == 3 and date[0] in month:
    date[1] = date.replace(",","")
    date[0] = month.index(date[0]) + 1
    print(f"{date[2]}-{int(date[0]):02}-{int(date[1]):02}")
    break


    except ValueError:
    continue


    enter image description here

    When I write September 8, 1636, there is no output.

    I want to write a code that convert input = September 8, 1636 to output= 1636-09-08 , input= 10/9/1701 to output= 1701-10-09 , input=10 December, 1815 ask to enter the input agian.

    Continue reading...

Compartilhe esta Página