Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Vending machine help
#3
Thanks, I went through and adjusted it - seems to have sorted that issues.. I am a little further through, and have got it working until I enter my coin into the machine.

I am not sure how to pull a method from my super class? I think I have everything I need to insert into the section but am unable to run that when the user inserts the coin value. It just gives me a value and doesn't call the method? Any help or comments to put me in the right direction will be appreciated!!

class Vending_Machine: 
    aussie_coins = (0.05, 0.10, 0.20, 0.50, 1.00, 2.00)
    items = ['Tea','Coffee', 'Coke', 'Orange Juice']
    item_price = [0.50, 1.00, 1.50, 1.00]
    item_code = ['1', '2', '3', '4']
    
    def __init__(self):
        self.total = 0.00
        
    def insert_coin(self,coin):
        if float(coin) not in (self.aussie_coins):
            print ('The Vending Machine accepts only: {}. ' .format(self.aussie_coins), end = '')
        else:
            self.total += coin
            print ('Currently there is a total of {: .2f} in machine' .format(self.total))
            
class interface(Vending_Machine):            
    def menu(self):
        print("##################################")
        print(" Welcome to My Vending Machine ")
        print("All items below are readily available")
        print(Vending_Machine.item_code[0], Vending_Machine.items[0], Vending_Machine.item_price[0]) #
        print(Vending_Machine.item_code[1], Vending_Machine.items[1], Vending_Machine.item_price[1])
        print(Vending_Machine.item_code[2], Vending_Machine.items[2], Vending_Machine.item_price[2])
        print(Vending_Machine.item_code[3], Vending_Machine.items[3], Vending_Machine.item_price[3])
        print("##################################")
        
class user_input(interface):
        def choice (self):
            choice = input("Please enter the item code of an item you would like to purchase: ")
            if choice == Vending_Machine.item_code[0]:
                print ("You have selected {} - the price is ${:.2f}. Currently you have a total of ${:.2f} in the machine." .format(Vending_Machine.items[0], Vending_Machine.item_price[0], self.total))
                if self.total < Vending_Machine.item_price[0]: #if not the price of tea then.. 
                    Vending_Machine.insert_coin = float(input("Insert a coin into the vending machine"))
                elif self.total > Vending_Machine.item_price[0]:
                    self.total -= Vending_Machine.item_price[0]
                    print('Please take your {}. Total of {:.2f} in the machine' .format(Vending_Machine.items[0],self.total))
                elif self.total == Vending_Machine.item_price[0]:
                    self.total -= Vending_Machine.item_price[0]
                    print('Please take your {}. Thanks, have a nice day!'.format(Vending_Machine.items[0]))
                
            elif choice == Vending_Machine.item_code[1]:
                print ("You have selected {} - the price is ${:.2f}. Currently you have a total of ${:.2f} in the machine." .format(Vending_Machine.items[1], Vending_Machine.item_price[1], self.total))
                if self.total < Vending_Machine.item_price[1]: #if not the price of tea then.. 
                    insert_coin(input("Insert a coin into the vending machine: "))
                elif self.total > Vending_Machine.item_price[1]:
                    self.total -= Vending_Machine.item_price[1]
                    print('Please take your {}. Total of {:.2f} in the machine' .format(Vending_Machine.items[1],self.total))
                elif self.total == Vending_Machine.item_price[1]:
                    self.total -= Vending_Machine.item_price[1]
                    print('Please take your {}. Thanks, have a nice day!'.format(Vending_Machine.items[1]))
        
            elif choice == Vending_Machine.item_code[2]:
                print ("You have selected {} - the price is ${.2f}. Currently you have a total of ${.2f} in the machine." .format(Vending_Machine.items[2], Vending_Machine.item_price[2], self.total))
                if self.total < Vending_Machine.item_price[1]: #if not the price of tea then.. 
                    insert_coin(input("Insert a coin into the vending machine: "))
                elif self.total > Vending_Machine.item_price[2]:
                    self.total -= Vending_Machine.item_price[2]
                    print('Please take your {}. Total of {:.2f} in the machine' .format(Vending_Machine.items[1],self.total))
                elif self.total == Vending_Machine.item_price[2]:
                    self.total -= Vending_Machine.item_price[2]
                    print('Please take your {}. Thanks, have a nice day!'.format(Vending_Machine.items[2]))
            
            elif choice == Vending_Machine.item_code[3]:
                print ("You have selected {} - the price is ${.2f}. Currently you have a total of ${.2f} in the machine." .format(Vending_Machine.items[3], Vending_Machine.item_price[3], self.total))
                if self.total < Vending_Machine.item_price[3]: #if not the price of tea then.. 
                    insert_coin(input("Insert a coin into the vending machine: "))
                elif self.total > Vending_Machine.item_price[3]:
                    self.total -= Vending_Machine.item_price[3]
                    print('Please take your {}. Total of {:.2f} in the machine' .format(Vending_Machine.items[3],self.total))
                elif self.total == Vending_Machine.item_price[3]:
                    self.total -= Vending_Machine.item_price[3]
                    print('Please take your {}. Thanks, have a nice day!'.format(Vending_Machine.items[3]))
            
                elif choice not in item_code:
                    print("Sorry we do not have item number {} available. Please try again" .format(choice))        
                    


            
vm = Vending_Machine()
i1 = interface()
u1 = user_input()

i1.menu()
u1.choice()
                
Reply


Messages In This Thread
Vending machine help - by wiggles - Apr-03-2020, 01:09 AM
RE: Vending machine help - by ndc85430 - Apr-03-2020, 03:50 AM
RE: Vending machine help - by wiggles - Apr-03-2020, 05:18 AM
RE: Vending machine help - by ndc85430 - Apr-03-2020, 07:14 AM
RE: Vending machine help - by wiggles - Apr-03-2020, 07:49 AM
RE: Vending machine help - by wiggles - Apr-04-2020, 05:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Vending Machine Project - OOP Issues wiggles 2 3,558 Apr-05-2020, 05:15 AM
Last Post: wiggles

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020