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


You can understand by Watching video :-



Answer :-

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

a = int (input("Enter the date  = " ))

month = a // 1000000
date = (a % 1000000) // 10000
year = a % 10000

print ( mon [ month - 1 ] , date ,", ", year )

Output :-

Enter the date  = 12252019
December 25  ,  2019

>>>

Enter the date  = 09162021
September 16  ,  2021

>>> 

Enter the date  = 11302020
November 30  ,  2020

>>>


4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. this will allow to output dates like feb 29 2005 or other dates that cannot exist like march 76 2021. How to solve that?

    ReplyDelete
    Replies
    1. Here we are handling error because program will become large.

      Delete
  2. OR we can also write as
    date=int(input('Enter date in the format=MMDDYYYY :'))
    sdate=str(date)
    month={'1':'January','2':'February','3':'March','4':'April','5':'May','6':'June','7':'July','8':'August','9':'September','10':'October','11':'November','12':'December'}
    n=month.keys()
    for j in month.keys():
    if sdate[:1]==j:
    print(month[j],end=' ')
    print(sdate[1:3],end='')
    print(',',sdate[3:8])

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post