If we have a class that has an instance e.g self.hawaii = 122
, where the key is the pizza type and the value is the stock, how can I reduce the stock value (by 22) after an "input/order" from another class?
# Dummy example
class Pizza:
def __init__(self):
# key: pizza_type
# value: stock available
self.hawaii = 122
self.funghi = 33
class Order(Pizza):
def order(self):
# For simplicity, I didn't use "input()"
order_type = "hawaii"
order_quantity = 22
for i, j in super().__dict__.items():
if i == order_type:
print(j)
j -= order_quantity
print(j)
for l in super().__dict__.items():
print(l)
if __name__ == '__main__':
b = Order()
b.order()
Output:
122
100
('hawaii', 122) ---> stays the same, I need 100 here
('funghi', 33)
Disclosure: I'm new to OOP.
I tried:
- self.get(order_type) --> Error
- self.order_type --> Error