0% found this document useful (0 votes)
20 views

Python

The document defines a Telephone class with methods like PrintInfo and AddContact. It then defines a Mobile class that inherits from Telephone and overrides methods like CallICE to handle mobile-specific functionality.

Uploaded by

Agerola
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Python

The document defines a Telephone class with methods like PrintInfo and AddContact. It then defines a Mobile class that inherits from Telephone and overrides methods like CallICE to handle mobile-specific functionality.

Uploaded by

Agerola
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

class Telephone:

def __init__(self, brand, telephoneType="UnknownType"):


self.id = random.randint(0, 1000000)
self.brand = brand
self.telephoneType = telephoneType
self.memory = {}

def PrintInfo(self):
print(self.telephoneType, self.brand)
for x in self.memory.items():
print(" ".join(x))

@staticmethod
def CallICE():
print("Method is not implemented")

def AddContact(self, surname, number):


if surname in self.memory:
print("The contact for given surname already exists in memory")
else:
self.memory[surname] = number

------------------------------------------------------------------------------

class Mobile(Telephone):
def __init__(self, brand, simCards, activeSimCard):
self.brand = brand
self.simCards = simCards if len(simCards) < 3 else simCards[:2]
self.activeSimCard = self.simCards[activeSimCard]
self.telephoneType = "Mobile"
self.id = random.randint(0,1000000)
self.memory = {}

def HasProductDefect(self):
if self.brand == "XYZBadBrand" and self.id % 333 == 0:
print("This mobile HAS product defect")
elif self.brand != "XYZBadBrand" and self.id % 999 == 0:
print("This mobile HAS product defect")
else:
print("This mobile HAS NO product defect")

def CallICE(self):
if len(self.memory) == 0:
print("There's no number in memory!")
else:
first_person = sorted(self.memory, key=lambda x: x)
print(first_person[0], self.memory[first_person[0]], self.activeSimCard)
def concatenate_string(string1, string2):
s = ""
for x in range(len(string1)):
s += string1[x]
s += string2[x]
return s

def pascal_triangle(num):
if num == 0:
return []
elif num == 1:
return [[1]]
else:
nrow = [1]
res = pascal_triangle(num-1)
lrow = res[-1]
for x in range(len(lrow)-1):
nrow.append(lrow[x] + lrow[x+1])
nrow += [1]
res.append(nrow)
return res

You might also like