Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Vending machine help
#1
Hi, I have a project to build a vending machine that must display items and balance of coins within the machine. I have done some work on it and am stuck on line 31 of my code. I have defined self.total however it is coming back as an invalid syntax? I am happy for you to critique my code however I am completely new to this, and I am trying to keep it simple. I have only completed the code for one item so far in my machine

Thanks in advance!

class Vending_Machine(object): 
    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))
               
    def menu():
        print("Welcome to my Vending Machine")
        print(item_code[0], items[0], item_price[0]) #using the dict. from vending machine class 
        print(item_code[1], items[1], item_price[1])
        print(item_code[2], items[2], item_price[2])
        print(item_code[3], items[3], item_price[3])
        
    def user_input(self, choice):
        choice = input("Please enter the item code of an item you would like to purchase: ")
        if choice == item_code[0]:
            print ("You have selected {} - the price is ${.2f}. Currently you have a total of ${.2f} in the machine." .format(items[0], item_price[0], self.total))
            while self.total < item_price[0]: #if not the price of tea then.. 
                insert_coin(input("Insert a coin into the vending machine: "))
            else self.total >= item_price[0]:
                 self.total -= item_price[0]
                    print('Please take your {}. Total of {:.2f} in the machine' .format(items[0],self.total))
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,609 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