Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON: My professor commented this on my code: did not setup the occurs on method correctly. It needs to have the same # of inputs

PYTHON:
My professor commented this on my code: did not setup the occurs on method correctly. It needs to have the same # of inputs in all sub classes.
Can anyone please check my code and explain what did I do wrong and how to fix the code according to what my professor commented.
my code:
1st file : Acct.py:
class Appt:
def __init__(self, month, day, year, desc):
self.month = month
self.day = day
self.year = year
self.desc = desc
def OccursOn(self, month, day, year):
pass
class Month(Appt):
def OccursOn(self, month):
if self.month == month:
return True
return False
class Day(Appt):
def OccursOn(self, day):
if self.day == day:
return True
return False
class Date(Appt):
def OccursOn(self, month, day, year):
if self.month == month and self.day == day and self.year == year:
return True
return False
2nd file : Appt Main code.py:
from Appt import *
# Sample appointments
appts =[
Month(3, None, None, "Dental cleaning"),
Month(12, None, None, "Root"),
Day(None,15, None, "Crown"),
Date(12,10,2024, "Braces adjustment"),
Date(11,15,2024, "Pull Teeth"),
]
# Ask user for input
date_input = input("Enter a date (MM DD YYYY): ").split()
month_input = int(date_input[0])
day_input = int(date_input[1])
year_input = int(date_input[2])
option = input("Enter 'Month', 'Day', or 'Date' to check against appointments: ").capitalize()
# Check for appointments based on user input
found = False
if option == "Month":
for appt in appts:
if isinstance(appt, Month) and appt.OccursOn(month_input):
print("Matching Appointment:", appt.desc)
found = True
elif option == "Day":
for appt in appts:
if isinstance(appt, Day) and appt.OccursOn(day_input):
print("Matching Appointment:",appt.desc)
found = True
elif option == "Date":
for appt in appts:
if isinstance(appt, Date) and appt.OccursOn(month_input, day_input,year_input):
print("Matching Appointment:",appt.desc)
found = True
if not found:
print("No appointments found.")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2017 For Windows Web And Database Applications

Authors: Corinne Hoisington

1st Edition

1337102113, 978-1337102117

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago