Professional Documents
Culture Documents
Class 30
Class 30
Class 30
Smiles
class electronics():
def __init__(self, quantity, unit_price, mfd):
self.quantity = quantity
self.unit_price = unit_price
self.mfd = mfd
self.ls_of_brand = self.get_brands()
def get_brand(self):
return self.brand
def get_totalAmount(self):
return self.quantity * self.unit_price
def get_brands(self):
brands ={}
def __init__(self):
print(“This is the demo for an electronic Store”)
def get_brands(self):
#get brand name
brands ={}
num-=1
return brands
New_elect2 = electronics()
C = new_elect2.get_brands()
For k in c:
print(k)
#Attempt 2:
class electronics():
#inputs in class is quantity = 4
def __init__(self):
# self.brands = this.get_brands()
print("This is the demo for an electronic Store")
def get_brands(self):
x = []
main_dict={}
num = int(input("Enter the number of brands you wish to enter: "))
while num>0:
brands = {}
b1 = input("Enter the brand name: ")
u1 = float(input("Enter the unit_price: "))
q1 = int(input("Enter the quantity: "))
brands["brand"] = b1
brands['quantity'] = q1
brands['unit price'] = u1
brands["total amount"]= self.get_totalAmount(q1, u1)
# print(brands)
main_dict[num] = brands
# x.append(brands)
print(main_dict)
num-=1
return main_dict
new_elect2 = electronics()
c = new_elect2.get_brands()
print(c)
#Attempt 3
class electronics():
#inputs in class is quantity = 4
def __repr__(self):
return f"""
Brand is {self.brand}
Quantity is {self.quantity}
unit_price is {self.unit_price}
Total is {self.total}
Category is {self.category}
"""
if __name__ == "__main__":
# input Data
l = [] # this list will contain all our input Data
num = int(input("Enter the number of items you wish to enter: "))
while num>0:
num-=1
for li in l:
print(li)
new_elect = electronics(li)
lst_elect.append(new_elect)
class Store():
def __init__(self):
self.category = list()
self.items = list()
def __repr__(self):
st = ""
for item in self.items:
st += f" {item}\n"
return st
#Attempt 4
# class creation starts
==========================================================================
==========================
class electronics():
def __init__(self, item_data):
self.category = 'electronics'
self.brand = item_data[0]
self.quantity = item_data[1]
self.unit_price = item_data[2]
self.total= self.quantity * self.unit_price
def __repr__(self):
return f"""
Category is {self.category}
Brand is {self.brand}
Quantity is {self.quantity}
unit_price is {self.unit_price}
Total is {self.total}
"""
class Store():
def __init__(self):
self.categories = list()
self.brands = list()
self.items = list()
def __repr__(self):
st = ""
for item in self.items:
st += f" {item}\n"
return st
def update_store_categories(self):
store_categories_lst = [_item.category for _item in self.items]
self.categories = list(set(store_categories_lst))
def update_store_brands(self):
store_brands_lst = [_item.brand for _item in self.items]
self.brands = list(set(store_brands_lst))
def update_store_attributes(self):
self.update_store_categories()
self.update_store_brands()
# class creation ends. main code starts below
==========================================================================
==========================
if __name__ == "__main__":
# input Data
l = [] # this list will contain all our input Data
num = int(input("Enter the number of items you wish to enter: "))
for i in range(1, num + 1):
# input data inputting
print('=' * 45)
print(f'Please enter data for item nos {i}:')
print('=' * 45)
b1 = input("Enter the brand name: ")
model = input("Enter the item model: ")
u1 = float(input("Enter the unit price: "))
q1 = int(input("Enter the quantity: "))