Answer to Question #181438 in Python for James Hart

Question #181438

I need help with an edhesive question and please dont put one of those "too hard to answer" things. Im trying to do a personal organizer in code but i have no idea what im doing so if you can help i would love that! the info is right here:

https://intro.edhesive.com/courses/55668/assignments/7530041?module_item_id=16590785

sample run:

What is the event: Math Exam

What is the month (number): 2

What is the date: 29

What is the year: 2017

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

What is the event: Birthday Party

What is the month (number): 6

What is the date: 31

What is the year: 2018

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


******************** List of Events ********************

Math Exam

Date: February 1, 2017

Birthday Party

Date: June 1, 2018

1
Expert's answer
2021-04-15T23:20:48-0400
eventName = []
eventMonth = []
eventDay = []
eventYear = []

def addEvent():
    userEventName = input("Enter event name: ")
    userEventMonth = int(input("Enter event month (1-12): "))
    userEventDay = int(input("Enter event day(1-31): "))
    userEventYear = int(input("Enter event year (Ex:2020): "))
    userEventMonth = validateMonth(userEventMonth)
    userEventDay = validateDay(userEventMonth,userEventDay,userEventYear)
    
    eventName.append(userEventName)
    eventMonth.append(userEventMonth)
    eventDay.append(userEventDay)
    eventYear.append(userEventYear)
    
def validateMonth(month):
    if month >= 1 and month <= 12:
        return month
    else:
        return 1

def validateDay(month,day,year):
    # invalid days
    if day < 1 or day > 31 :
        return 1
    
    # if the month is february
    if month == 2:
        isleap = False
        if year%4 == 0:
            if year%100 == 0:
                if year%400 == 0:
                    isleap = True
            else:
                isleap = True
        # if the year is leap
        if isleap:
            if day < 30:
                return day
            else:
                return 1
        else:
             if day < 29:
                return day
             else:
                return 1
            
     # month with 31 days
    if month in [1,3,5,7,8,10,12]:
        return day
     # month with 30 days
    if month in [4,6,9,11] and day < 31:
        return day
    else:
        return 1
            
def printEvents():
    print("****** LIST OF EVENTS *********")
    
    months = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
          'August', 'September', 'October', 'November', 'December']
    
    for index in range(len(eventName)):
        print(eventName[index])
        print("Date: "+months[eventMonth[index] -1]+ " " + str(eventDay[index]) + ", " + str(eventYear[index]))

def printEventsForMonth(month):
    months = ['January', 'February', 'March', 'April', 'May', 'June', 'July',
          'August', 'September', 'October', 'November', 'December']
    print("****** EVENTS IN " + months[month -1] + " *********")
    
    for index in range(len(eventName)):
        if eventMonth[index] == month:
            print(eventName[index])
            print("Date: "+months[eventMonth[index] -1]+ " " + str(eventDay[index]) + ", " + str(eventYear[index]))
            
userChoice = "yes"
while userChoice.upper() != "NO":
    addEvent()
    userChoice = input("Do you want to enter another event? NO to stop: ") 
printEvents()
month = int(input("What month would like to see?(Enter the month number) " ))
month = validateMonth(month)
printEventsForMonth(month)


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS