Write a class named Person with data attributes for a person’s name, address, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number, and a Boolean data attribute indicating whether the customer wishes to be on a mailing list. Demonstrate an instance of the Customer class in a simple program. PreviousNext

Respuesta :

Following are the python program to the given question:

Program Explanation:

  • Defining a base class "Person".
  • Inside the class, a constructor is defined that takes three parameters "name, address, and telephone", in which self is used to hold value into the variable.
  • In the next step, a child class "Customer" is declared that inherits the base class "Person".
  • Inside the class, a constructor is defined that takes five parameters "name, address, telephone, customer_number, and onMailList", which is called the base class constructor, and use self is used to hold other variable values.
  • In the next step, a variable "o" is defined that calls the "Customer" class constructor by accepting value in parameter and using a print method to print its value.  

Program:

class Person:#defining a class Person

   def __init__(self, name, address, telephone):#defining a constructor that takes three parameters

       self.name = name#holding name value  

       self.address = address#holding address value  

       self.telephone = telephone#holding telephone value  

class Customer(Person):#defining a class Customer that inherits the Person class

   def __init__(self, name, address, telephone, customer_number, onMailList):#defining constructor that takes parameters

       Person.__init__(self, name, address, telephone)#calling Person class constructor

       self.customer_number = customer_number#holding cusNum value  

       self.onMailList = onMailList#holding onMailList value  

o = Customer("DEV", "Singpur", 9307885478, 301, True)#defining a variable obj that calls the Customer by accepting parameters

#printing the values

print("Name: " + o.name)#print name

print("Address: " + o.address)#print address

print("Telephone: " + str(o.telephone))#print telephone

print("Customer Number: " + str(o.customer_number))#print Customer Number

print("Wish to be on mail list: " + str(o.onMailList))#print mail value

Output:

Please find the attached file.

Learn more:

brainly.com/question/17199574

Ver imagen codiepienagoya
ACCESS MORE