114k views
0 votes
Write the definition of a class Phone containing: 1. A data member named model of type string. 2. A data member named partNumber of type string. 3. A data member named retailPrice of type double 4. A void method to display the fields model, partNumber, and retailPrice on the standard output.

1 Answer

4 votes

Answer:

class Phone(object):

def __init__(self, model, partNumber, retailPrice):

self.model = model

self.part_number = partNumber

self.retail_price = retailPrice

def phone_specs(self):

print( "Phone model: {}\\Part number: {}\\Retail price: {}".format( self.model, self.part_number, self.retail_price))

phone1 = Phone("Nokia", "asd234", 200.0)

phone1.phone_specs()

Step-by-step explanation:

A class is a blueprint of a data structure used to create objects of the same data types and methods. The Phone class is an object that creates an instance of the phone1 object. The phone_specs method is used to display the details of the phone1 object.

User Malcolm Murdoch
by
3.5k points