Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
class Phone(object):
def __init__(self, phnname, modelname, storage, price):
self.phnname = phnname
self.modelname = modelname
self.storage = storage
self.price = price

def getphnname(self):
return self.phnname

def getmodelname(self):
return self.modelname

def getstorage(self):
return self.storage

def getprice(self):
return self.price

class Huawei(Phone):
def __init__(self):
Phone.__init__(self, "Huawei Nova", "3i", "4GB RAM", 35999)

def getinfo(self):
print(self.phnname, self.modelname, \n "Storage:", self.storage, \n "Price:", self.price)

Huawei.getinfo()

What I have tried:

I want it to output the information about the phone but it is giving me error in print so what should I change for it to work p.s new to programming
Posted
Updated 25-May-21 4:30am

1 solution

Python
print(self.phnname, self.modelname, \n "Storage:", self.storage, \n "Price:", self.price)
#                                    ^                            ^
# These are illegal characters like this they must be inside quotes to work:

print(self.phnname, self.modelname, "\nStorage:", self.storage, "\nPrice:", self.price)
# Like this                           ^                           ^

But a better way would be to use one print statement per line rather than doing it the way you have.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900