Jan-05-2019, 02:53 PM
To define a class and subclasses, use the class keyword:
For your code, I would make the items in items() into attributes under Vending_Machine. They would also be a pair of dicts instead of a trio of lists. By the way, lines 11 through 27 on items() don't really do anything.
Now, subclasses need to make sense in relation to their superclass. Vending_Machine being the superclass of Balance, Items, and Keypad doesn't make sense (e.g. a Keypad is not a vending machine in real life). For what you have, Vending_Machine, Keypad, and Item make sense and the last two make sense as objects stored inside Vending_Machine, not as subclasses though.
Try reorganizing your code under a few classes and we can provide more advice.
class Vending_Machine: def __init__(self): # init constructs the class at instantiation pass def Balance(Vending_Machine): def __init__(self): passAs for organizing your code, methods can be defined by defining a function indented under the definition of the class (as above). In Python, there is no distinction of public or private when it comes to methods and attributes. The convention is to use a leading underscore for private methods and attributes, but it does nothing in the interpretter.
For your code, I would make the items in items() into attributes under Vending_Machine. They would also be a pair of dicts instead of a trio of lists. By the way, lines 11 through 27 on items() don't really do anything.
Now, subclasses need to make sense in relation to their superclass. Vending_Machine being the superclass of Balance, Items, and Keypad doesn't make sense (e.g. a Keypad is not a vending machine in real life). For what you have, Vending_Machine, Keypad, and Item make sense and the last two make sense as objects stored inside Vending_Machine, not as subclasses though.
Try reorganizing your code under a few classes and we can provide more advice.