Computer Science, asked by gazdon617, 4 months ago

This is Part 2 of the Assignment 8: Personal Organizer

Attachments:

Answers

Answered by allysia
3

Language:

Python

Program:

def addEvent():

   global record

   record=[]

   while True:

       event=input("What is the event:")

       month=int(input("What is the month (number): "))

       date=int(input("What is the date: "))

       year=int(input("What is the year: "))

       record.append([event,[month,date,year]])

       choice= input("Do you want to enter another event? NO to stop: " )

       if choice=="NO":

           break

eventMonth={1:'January', 2:'February', 3:'March', 4:'April', 5:'May', 6:'June', 7:'July', 8:'August', 9:'September' , 10:'October' , 11:'November' , 12:'December'}

def printEvents():

   print('*'*15+'Event list'+ '*'*15)

   for i in range(len(record)):

       print(record[i][0])

       print(f"Date: {eventMonth[record[i][1][0]]} {record[i][1][1]}, {record[i][1][2]}  ")

   

Output :

After calling addEvent():

What is the event:Birthday  

What is the month (number): 8  

What is the date: 6  

What is the year: 2020  

Do you want to enter another event? NO to stop: Yes  

What is the event:Hour of Co_de  

What is the month (number): 12  

What is the date: 5  

What is the year: 2019  

Do you want to enter another event? NO to stop: NO

After calling printEvents():

* * * * * * * * * * * * * * *Event list* * * * * * * * * * * * * * *

Birthday  

Date: August 6, 2020  

Hour of Co_de

Date: December 5, 2019  

Explanation:

  • define addEvent() and get input thought while loop saving it in a list called record.
  • global keyword is used before record to make it accessible to program outside the function.
  • define a dictionary  eventMonth with numbers and month name.
  • under printEvents() function print the element as per need from record and use month as key to get value from dictionary.

Attachment:

Attachments:
Similar questions