Here’s how you can create the program for keeping track of boxes in a doctor’s office, following your prompts step by step.
1) Defining the Box
Class
class Box:
def __init__(self, date, contents, location):
self.date = date
self.contents = contents
self.location = location
2) Creating Instances of the Class
box_23 = Box("2016", "medical records", "storage closet")
box_21 = Box("2018", "lotion samples", "waiting room")
box_07 = Box("2020", "flyers about flu shot", "receptionist's desk")
3) Printing Attributes of Instances
print(box_23.date) # Printing the date of box #23
print(box_07.contents) # Printing the contents of box #07
print(box_21.location) # Printing the location of box #21
4) Method to Check Identical Attributes
def are_identical(box1, box2):
return (box1.date == box2.date and
box1.contents == box2.contents and
box1.location == box2.location)
5) Creating Box #10 and Comparing Attributes
box_10 = Box("2020", "flyers about flu shot", "receptionist's desk") # Box #10 identical to Box #07
# Comparing contents of Box #07 and Box #10
print(are_identical(box_07, box_10)) # Should return True
# Comparing contents of Box #21 and Box #23
print(are_identical(box_21, box_23)) # Should return False
Complete Program
Combining all the steps, the complete code looks like this:
class Box:
def __init__(self, date, contents, location):
self.date = date
self.contents = contents
self.location = location
box_23 = Box("2016", "medical records", "storage closet")
box_21 = Box("2018", "lotion samples", "waiting room")
box_07 = Box("2020", "flyers about flu shot", "receptionist's desk")
print(box_23.date) # Box #23 date
print(box_07.contents) # Box #07 contents
print(box_21.location) # Box #21 location
def are_identical(box1, box2):
return (box1.date == box2.date and
box1.contents == box2.contents and
box1.location == box2.location)
box_10 = Box("2020", "flyers about flu shot", "receptionist's desk") # Box #10 identical to Box #07
print(are_identical(box_07, box_10)) # Comparing Box #07 and Box #10
print(are_identical(box_21, box_23)) # Comparing Box #21 and Box #23
You can run this Python code to keep track of the boxes in a doctor's office as specified in the prompts.