I am working on simple vending machine.
I have a quick question about class and subclass method.
What I want to ask here, I have subclass "Deposit", and In a while loop,
- I would like to return 'Y' if selection method in class is int, and I would like to return 'V' if selection method in class is str.
This is because I would like to keep adding the coin value that is inserted in vending machine until the code run.
But, when I run a code, it always gave me 'V' no matter what I entered in input.
If you guys can help me designing deposit system, it would be better for me, but if you guys can help me to figure out the question that I ask, it will help me a lot to understand the class!
Thank you so much for reading poor description, anyone who does not make sense what I am asking, please comment! Thank you so much again.
def __init__(self, selection, soda):
self.__selection = selection
self.__soda = soda
self.balance = 0
def selection(self):
return self.__selection
def soda(self):
return self.__soda
def outofstock(self):
if stock[self.__soda] == 0:
return 'X'
else:
return " "
class Deposit(Vending):
Total = 0
def __init__ (self, selection, soda):
Vending.__init__(self, selection, soda)
self.balance = 0
def Deposit_coin(self):
if self.selection() == int:
return 'Y'
else:
return 'V'
Accept_coint = [5, 10, 25]
drink = ['Coke', 'Jolt', 'Pepsi', 'Diet']
stock = {'Coke':2, 'Jolt':2, 'Pepsi':2, 'Diet':2}
while True:
print ('---------------------------------')
if 0 not in stock.values():
print (' {} ( ) {} ( )'.format(drink[0], drink[1]))
print (' {} ( ) {} ( )'.format(drink[2], drink[3]))
else:
print (' {} ({}) {} ({})'.format(drink[0], Vending(__, drink[0]).outofstock(), drink[1], Vending(__, drink[1]).outofstock()))
print (' {} ({}) {} ({})'.format(drink[2], Vending(__, drink[2]).outofstock(),drink[3],Vending(__, drink[3]).outofstock()))
a = Deposit(input(), __)
print(a.Deposit_coin())```