Hi so i have a program that i wrote and the critiques on what i need to fix. can someone fix what needs to be fixed for me?
(THIS IS WHAT ALL NEEDS TO BE FIXED)
For this question, there are no options about what the user can do. The only functionality is that they get asked for events in a loop (controlled by asking if they want to enter another event), then once they've said "NO" to that, printEvents gets called, then they're asked for a month number, then printMonth gets called.
Beyond that, addEvent should handle only one event - the while loop and the input asking if they want to enter another event should be outside, in the main part of the program (and addEvent gets called in that loop). You also call number_of_days using the day value instead of the year one.
you also have a far number of errors in printMonth, and one that's also in printEvents. You're missing a comma in between "August" and "September" in your month names array, which causes the list indexes to go out of bounds there, and instead of accessing
months[eventMonth[month]-1]
in printMonth, which is meaningless - this is attempting to index into eventMonth using the selected month number - you should just be doing
months[month-1]
You also then try to compare eventMonth, an array, to month, which isn't going to work - you want to be checking the month of the current event, eventMonth[i]. You don't currently print the event name at all here.
(THIS IS THE PROGRAM)
def leap_year(y):
if y % 400 == 0:
return 1
elif y % 100 == 0:
return 0
elif y % 4 == 0:
return 1
else:
return 0
def number_of_days(m, y):
ld = leap_year(y)
if (m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 or m == 12):
return 31
elif (m == 4 or m == 6 or m == 9 or m == 11):
return 30
elif (m == 2):
return 28 + ld
def addEvent(eventName, eventMonth, eventDay, eventYear):
cont = True
while cont == True:
newName = input("What is the event: ")
newMonth = int(input("What is the month (number): "))
newDay = int(input("What is the date: "))
newYear = int(input("What is the year: "))
eventName.append(newName)
if newMonth < 1 or newMonth > 12:
newMonth = 1
eventMonth.append(newMonth)
numDays = number_of_days(newMonth, newDay)
if newDay < 1 or newDay > numDays:
newDay = 1
eventDay.append(newDay)
eventYear.append(newYear)
ans = input("Do you want to enter another event? Type NO to stop. ")
if ans == "NO":
cont = False
def printEvents(eventName, eventMonth, eventDay, eventYear):
months = ['January','February','March','April','May','June','July','August' 'September','October','November','December']
print("******************* List of Events *******************")
for i in range(len(eventName)):
print(eventName[i])
print("Date: " + str(months[eventMonth[i]-1]) + " " + str(eventDay[i]) + ", " + str(eventYear[i]))
def printMonth(month,eventName, eventMonth, eventDay, eventYear):
months = ['January','February','March','April','May','June','July','August' 'September','October','November','December']
if month < 1 or month > 12:
month = 1
print("************ Events in " + months[eventMonth[month]-1] + " *************")
for i in range(len(eventName)):
if (eventMonth == month):
print("Date: " + str(months[eventMonth[i]-1]) + " " + str(eventDay[i]) + ", " + str(eventYear[i]))
### Main Program ###
eventName = []
eventMonth = []
eventDay = []
eventYear = []
quit = True
while quit == True:
choice = int(input("Make your selection (1 Add Events , 2 Print all events , 3 Print Selected Month , or 4 Quit ): "))
print("\n\n")
if choice == 4:
quit = False
elif choice == 1:
addEvent(eventName, eventMonth, eventDay, eventYear)
elif choice == 2:
printEvents(eventName, eventMonth, eventDay, eventYear)
elif choice == 3:
month = int(input("What month would you like to see? (Enter the month number: )"))
print("\n")
printMonth(month, eventName, eventMonth, eventDay, eventYear)
else:
print("Invalid choice, try again")
print("\n\n")
Answers
Answered by
0
Answer:
elif choice == 3:
month = int(input("What month would you like to see? (Enter the month number: )"))
print("\n")
printMonth(month, eventName, eventMonth, eventDay,
Answered by
2
Answer:
quit = True
while quit == True:
choice = int(input("Make your selection (1 Add Events , 2 Print all events , 3 Print Selected Month , or 4 Quit ): "))
print("\n\n")
if choice == 4:
quit = False
elif choice == 1:
addEvent(eventName, eventMonth, eventDay, eventYear
else:print("Invalid choice, try again")
elif choice == 3:month = int(input("What month would you like to see? (Enter the month number: )"))print("\n")printMonth(month, eventName, eventMonth, eventDay, eventYear)else:print("Invalid choice, try again")print("\n\n")
- hope it helps you...
- please mark it as a brainlist answer..
- also please rate thanks and follow me...
- stay home STAY SAFE...
Similar questions