class WorkoutClass:
"""A workout class that can be offered at a gym.
=== Private Attributes ===
_name: The name of this WorkoutClass.
_required_certificates: The certificates that an instructor must
hold to
teach this WorkoutClass.
"""
_name: str
_required_certificates: List[str]
def __init__(self, name: str, required_certificates: List[str])
-> None:
"""Initialize a new WorkoutClass called <name> and with
the
<required_certificates>.
>>> workout_class = WorkoutClass('Kickboxing',
['Strength Training'])
>>> workout_class.get_name()
'Kickboxing'
"""
def get_name(self) -> str:
"""Return the name of this WorkoutClass.
>>> workout_class = WorkoutClass('Kickboxing',
['Strength Training'])
>>> workout_class.get_name()
'Kickboxing'
"""
def get_required_certificates(self) -> List[str]:
"""Return all the certificates required to teach this
WorkoutClass.
>>> workout_class = WorkoutClass('Kickboxing',
['Strength Training'])
>>> workout_class.get_required_certificates()
['Strength Training']
"""
class Instructor:
"""An instructor at a Gym.
Each instructor may hold certificates that allows them to teach
specific
workout classes.
=== Public Attributes ===
name: This Instructor's name.
=== Private Attributes ===
_id: This Instructor's identifier.
_certificates: The certificates held by this Instructor.
"""
name: str
_id: int
_certificates: List[str]
def __init__(self, instructor_id: int, instructor_name: str)
-> None:
"""Initialize a new Instructor with an and their
. Initially, the instructor holds no certificates.
>>> instructor = Instructor(1, 'Matylda')
>>> instructor.get_id()
1
>>> instructor.name
'Matylda'
"""
implementation omittted
def get_id(self) -> int:
"""Return the id of this Instructor.
>>> instructor = Instructor(1, 'Matylda')
>>> instructor.get_id()
1
"""
implementation omitted
def add_certificate(self, certificate: str) -> bool:
"""Add the to this instructor's list of certificates iff
this instructor does not already hold the .
Return True iff the was added.
>>> instructor = Instructor(1, 'Matylda')
>>> instructor.add_certificate('Strength Training')
True
>>> instructor.add_certificate('Strength Training')
False
"""
implementation omitted
def get_num_certificates(self) -> int:
"""Return the number of certificates held by this instructor.
>>> instructor = Instructor(1, 'Matylda')
>>> instructor.add_certificate('Strength Training')
True
>>> instructor.get_num_certificates()
1
"""
implementation omitted
def can_teach(self, workout_class: WorkoutClass) ->
bool:
"""Return True iff this instructor has all the required
certificates to
teach the workout_class.
>>> matylda = Instructor(1, 'Matylda')
>>> kickboxing = WorkoutClass('Kickboxing', ['Strength
Training'])
>>> matylda.can_teach(kickboxing)
False
>>> matylda.add_certificate('Strength Training')
True
>>> matylda.can_teach(kickboxing)
True
"""
implementation omitted
class Gym:
"""A gym that hosts workout classes taught by instructors.
All offerings of workout classes start on the hour and are 1 hour long.
=== Public Attributes ===
name: The name of the gym.
=== Private Attributes ===
_instructors: The roster of instructors who work at this Gym.
Each key is an instructor's ID and its value is the Instructor
object
representing them.
_workouts: The workout classes that are taught at this Gym.
Each key is the name of a workout class and its value is the
WorkoutClass object representing it.
_rooms: The rooms in this Gym.
Each key is the name of a room and its value is its capacity, that
is,
the number of people who can register for a class in this
room.
_schedule: The schedule of classes offered at this gym. Each key is
a date
and time and its value is a nested dictionary describing all
offerings
that start then. Each key in the nested dictionary is the name of a
room
that has an offering scheduled then, and its value is a tuple
describing
the offering. The tuple elements record the instructor teaching
the
class, the workout class itself, and a list of registered clients.
Each
client is represented by a unique string.
=== Representation Invariants ===
- Each key in _schedule is for a time that is on the hour.
- No instructor is recorded as teaching two workout classes at the
same
time.
- No client is recorded as registered for two workout classes at
the same
time.
- If an instructor is recorded as teaching a workout class, they
have the
necessary qualifications.
- If there are no offerings scheduled at date and time in room
then
does not occur as a key in _schedule[d]
- If there are no offerings at date and time in any room at all,
then
does not occur as a key in _schedule
"""
name: str
_instructors: Dict[int, Instructor]
_workouts: Dict[str, WorkoutClass]
_rooms: Dict[str, int]
_schedule: Dict[datetime,
Dict[str, Tuple[Instructor, WorkoutClass, List[str]]]]
def __init__(self, gym_name: str) -> None:
"""Initialize a new Gym with that has no instructors, workout
classes, rooms, or offerings.
>>> ac = Gym('Athletic Centre')
>>> ac.name
'Athletic Centre'
"""
self.name = gym_name
self._instructors = {}
self._workouts = {}
self._rooms = {}
self._schedule = {}
def schedule_workout_class(self, time_point: datetime,
room_name: str,
workout_name: str, instr_id: int) -> bool:
"""Add an offering to this Gym at a iff:
- the room with is available,
- the instructor with is qualified to teach the workout
class with , and
- the instructor is not teaching another workout class during
the
same .
A room is available iff it does not already have another workout
class
scheduled at that date and time.
The added offering should start with no registered clients.
Return True iff the offering was added.
Preconditions:
- The room has already been added to this Gym.
- The Instructor has already been added to this Gym.
- The WorkoutClass has already been added to this Gym.
>>> ac = Gym('Athletic Centre')
>>> diane = Instructor(1, 'Diane')
>>> ac.add_instructor(diane)
True
>>> diane.add_certificate('Cardio 1')
True
>>> ac.add_room('Dance Studio', 50)
True
>>> boot_camp = WorkoutClass('Boot Camp', ['Cardio
1'])
>>> ac.add_workout_class(boot_camp)
True
>>> sep_9_2019_12_00 = datetime(2019, 9, 9, 12, 0)
>>> ac.schedule_workout_class(sep_9_2019_12_00, 'Dance
Studio',\
boot_camp.get_name(), diane.get_id())
True
"""
#IMPLEMENT METHOD
def instructor_hours(self, time1: datetime, time2: datetime)
-> \
Dict[int, int]:
"""Return a dictionary reporting the hours worked by
instructors
between and , inclusive.
Each key is an instructor ID and its value is the total number
of hours
worked by that instructor between and inclusive. Both
and specify the start time for an hour when an
instructor may have taught.
Precondition: time1 < time2
>>> ac = Gym('Athletic Centre')
>>> diane = Instructor(1, 'Diane')
>>> david = Instructor(2, 'David')
>>> diane.add_certificate('Cardio 1')
True
>>> ac.add_instructor(diane)
True
>>> ac.add_instructor(david)
True
>>> ac.add_room('Dance Studio', 50)
True
>>> boot_camp = WorkoutClass('Boot Camp', ['Cardio
1'])
>>> ac.add_workout_class(boot_camp)
True
>>> t1 = datetime(2019, 9, 9, 12, 0)
>>> ac.schedule_workout_class(t1, 'Dance Studio',
boot_camp.get_name(),
... 1)
True
>>> t2 = datetime(2019, 9, 10, 12, 0)
>>> ac.instructor_hours(t1, t2) == {1: 1, 2: 0}
True
"""
# IMPLEMENT METHOD!
This is a part of a greater assignment that I'm working on and I've tried implementing these methods but I just wanted to see a different, more concise way to implement them! any help is appreciated because my code for these functions is too long. Please help with function schedule_workout_class and instructor_hours
class WorkoutClass: """A workout class that can be offered at a gym. === Private Attributes ===...
reate a class called Person with the following attributes: name - A string representing the person's name age - An int representing the person's age in years As well as appropriate __init__ and __str__ methods, include the following methods: get_name(self) - returns the name of the person get_age(self) - returns the age of the person set_name(self, new_name) - sets the name for the person set_age(self, new_age) - sets the age for the person is_older_than(self, other) - returns True if this...
Use your Food class, utilities code, and sample data from Lab 1 to complete the following Tasks. def average_calories(foods): """ ------------------------------------------------------- Determines the average calories in a list of foods. foods is unchanged. Use: avg = average_calories(foods) ------------------------------------------------------- Parameters: foods - a list of Food objects (list of Food) Returns: avg - average calories in all Food objects of foods (int) ------------------------------------------------------- """ your code here is the...
Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...
PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...
PYHTON Preliminaries For this assignment you will be working with the following classes, which are available in the file homework5-classes.py: class Pharmacy: def _init_(self, inventory, unit_prices) self.inventory - inventory self.unit_prices-unit_prices class Prescription: definit_(self, patient, drug_name, quantity): self.patient- patient self.drug_namedrug_name self.quantity - quantity You will be asked to write several functions that work with the Prescription and Pharmacy classes. To complete this assignment you may write any helper functions you like inside your homework5.py file. Pharmacy class attributes: * inventory: A...
python Preliminaries For this assignment you will be working with the following classes, which are available in the file homework5-classes.py: class Pharmacy: def _init_(self, inventory, unit_prices) self.inventory - inventory self.unit_prices-unit_prices class Prescription: definit_(self, patient, drug_name, quantity): self.patient- patient self.drug_namedrug_name self.quantity - quantity You will be asked to write several functions that work with the Prescription and Pharmacy classes. To complete this assignment you may write any helper functions you like inside your homework5.py file. Pharmacy class attributes: * inventory: A...
python 3 question Project Description Electronic gradebooks are used by instructors to store grades on individual assignments and to calculate students’ overall grades. Perhaps your instructor uses gradebook software to keep track of your grades. Some instructors like to calculate grades based on what is sometimes called a “total points” system. This is the simplest way to calculate grades. A student’s grade is the sum of the points earned on all assignments divided by the sum of the points available...
Objectives You will implement and test a class called MyString. Each MyString object keeps track of a sequence of characters, similar to the standard C++ string class but with fewer operations. The objectives of this programming assignment are as follows. Ensure that you can write a class that uses dynamic memory to store a sequence whose length is unspecified. (Keep in mind that if you were actually writing a program that needs a string, you would use the C++ standard...