You are on page 1of 7

Chinanu, oya make it happen!

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 ={}

num = int(input("Enter the number of brands you wish to enter: "))


while num>0:
b1 = input("Enter the brand name: ")
U1 = float(input(“Enter the unit_price: “))
Q1 = int(input(“Enter the quantity: ”))
brands.update({"brand": b1})
brands.update({“unit_price”: u1})
brands.update({“quantity”: q1})
num-=1
return brands

New_elect = electronics(10, 10000, "10-08-2022")


print(New_elect.ls_of_brand)
class electronics():
#inputs in class is quantity = 4

def __init__(self):
print(“This is the demo for an electronic Store”)

def get_totalAmount(self,q, u):


return q * u

def get_brands(self):
#get brand name
brands ={}

num = int(input("Enter the number of brands you wish to enter: "))


while num>0:
b1 = input("Enter the brand name: ")
U1 = float(input(“Enter the unit_price: “))
Q1 = int(input(“Enter the quantity: “))
brands.update({"brand": b1})
brands.update({“quantity”:q1})
brands.update({“total amount”: self.get_totalAmount(q1, u1)})

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_totalAmount(self,q, u):


return q * u

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 __init__(self, item_data):


self.brand = item_data[0]
self.quantity = item_data[1]
self.unit_price = item_data[2]
self.total= self.quantity * self.unit_price
self.category = 'electronics'

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:

# input data inputting


b1 = input("Enter the brand name: ")
u1 = float(input("Enter the unit price: "))
q1 = int(input("Enter the quantity: "))
model = input("Enter the item model: ")
# adding data to instance of input data
l.append([b1,u1,q1,model])

num-=1

# adding each input data an electronic class


lst_elect = list()

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 store_list_of_items(self, ls):


for item in ls:
self.items.append(item)

def store_item(self, item):


self.items.append(item)

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 store_list_of_items(self, ls):


for item in ls:
self.items.append(item)
self.update_store_attributes()

def store_item(self, item):


self.items.append(item)
self.update_store_attributes()

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: "))

# adding data to instance of input data


l.append([b1,u1,q1,model])

# feeding the item list in l to a electronic class


lst_elect = list()
for indx, li in enumerate(l):
print(f'item nos {indx}|item data: {li}')
new_elect = electronics(li) # adding each input data an
electronic class
lst_elect.append(new_elect) # a list of electronic classes

#new additions to code from 20230507


#entering the electronic items as a list of items to the Store class
store = Store()
store.store_list_of_items(lst_elect)
print(store.categories)
print(store.brands)

You might also like