[Type C] Python Revision Tour-1 – Chapter 1

|
Table of Contents

8. Write a program that reads a date as integers in the format MMDDYYYY. The program will call a function that prints out the date in the format <month name> <day>,<year>.

def print_date(month, day, year):
    months = ["January", "February", "March", "April", "May", "June", "July",
              "August", "September", "October", "November", "December"]
    month_name = months[month - 1]
    print(f"{month_name} {day},{year}")

# Example usage:
date = input("Enter the date in MMDDYYYY format: ")
month = int(date[:2])
day = int(date[2:4])
year = int(date[4:])
print_date(month, day, year)
Output
Enter the date in MMDDYYYY format: 03252022
March 25,2022
"Spread the light within, illuminate the hearts around you. Sharing is not just an action, but a sacred journey of connecting souls."~ Anonymous

Leave a Reply

Your email address will not be published. Required fields are marked *