164k views
2 votes
Write in Python

11.3

Write in Python 11.3-example-1
User Mislav
by
8.1k points

1 Answer

0 votes

Answer:

A simple program of the Person and Customer classes in Python

class Person:

def __init__(self, name, address, telephone_number):

self.name = name

self.address = address

self.telephone_number = telephone_number

class Customer(Person):

def __init__(self, name, address, telephone_number, customer_number, mailing_list):

super().__init__(name, address, telephone_number)

self.customer_number = customer_number

self.mailing_list = mailing_list

# Creating an instance of the Customer class

customer1 = Customer("John Doe", "123 Main St", "555-1234", "C12345", True)

# Accessing attributes of the customer

print("Customer Name:", customer1.name)

print("Customer Address:", customer1.address)

print("Customer Telephone Number:", customer1.telephone_number)

print("Customer Number:", customer1.customer_number)

print("Wants to be on Mailing List:", customer1.mailing_list)

Step-by-step explanation:

In this example, the Person class is the base class, and the Customer class is a subclass of Person. The Person class has data attributes for a person's name, address, and telephone number. The Customer class extends the Person class and adds two additional data attributes: customer_number and mailing_list.

The __init__ method is used to initialize the attributes of each class. The super().__init__() call in the Customer class ensures that the attributes from the Person class are also initialized properly.

Finally, an instance of the Customer class (customer1) is created and its attributes are accessed and printed in a simple program.

User Dlinet
by
7.5k points

No related questions found