DEV Community 👩‍💻👨‍💻

Cover image for Date Converter
Scott Gordon
Scott Gordon

Posted on

Date Converter

#     Converts day month and year numbers into two date formats
#     using string format or f string.
# by: Scott Gordon

def main():
    # get the day month and year as numbers
    day = int(input("Enter the day number: "))
    month = int(input("Enter the month number: "))
    year = int(input("Enter the year: "))

    date1 = str(month)+"/"+str(day)+"/"+str(year)

    months = ["January", "February", "March", "April",
              "May", "June", "July", "August",
              "September", "October", "November", "December"]
    monthStr = months[month-1]
    date2 = monthStr+" " + str(day) + ", " + str(year)

    # print("The date is", date1, "or", date2+".") # using string concatenation
    # print("The date is {0} or {1}.".format(date1, date2)) # using string format method
    print(f"The date is {date1} or {date2}.")  # using f string

Enter fullscreen mode Exit fullscreen mode

Top comments (0)

🌚 Life is too short to browse without dark mode