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
>>>
this will allow to output dates like feb 29 2005 or other dates that cannot exist like march 76 2021. How to solve that?
ReplyDeleteHere we are handling error because program will become large.
DeleteOR we can also write as
ReplyDeletedate=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])
Your answer is also correct.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )