-
Notifications
You must be signed in to change notification settings - Fork 0
/
classes.py
27 lines (21 loc) · 859 Bytes
/
classes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Store:
def __init__(self, name):
self.name = name
self.items = []
# You'll need 'name' as an argument to this method.
# Then, initialise 'self.name' to be the argument, and 'self.items' to be an empty list.
def add_item(self, name, price):
self.items.append({'name': name, 'price': price})
# Create a dictionary with keys name and price, and append that to self.items.
def stock_price(self):
return sum([ item['price'] for item in self.items])
# total = 0
# for item in self.items:
# total += item['price']
# return(total)
# Add together all item prices in self.items and return the total.
ramStore = Store('Ramstore')
ramStore.add_item('Huita', 22)
ramStore.add_item('Pizdota', 56)
print(ramStore.items)
print(ramStore.stock_price())