1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Levart [38]
3 years ago
11

Develop a program working as a soda vending machine. The program should show the product menu with price and take user input for

product number, quantity and pay amount. The output should show the total sale price including tax and the change. Organize the program with 4 functions and call them in main() based on the requirements.
Computers and Technology
1 answer:
Kipish [7]3 years ago
8 0

Answer:

Explanation:

The following vending machine program is written in Python. It creates various functions to checkItems, check cash, check stock, calculate refund etc. It calls all the necessary functions inside the main() function. The output can be seen in the attached picture below.

class Item:

   def __init__(self, name, price, stock):

       self.name = name

       self.price = price

       self.stock = stock

   def updateStock(self, stock):

       self.stock = stock

   def buyFromStock(self):

       if self.stock == 0:

           # raise not item exception

           pass

       self.stock -= 1

class VendingMachine:

   def __init__(self):

       self.amount = 0

       self.items = []

   def addItem(self, item):

       self.items.append(item)

   def showItems(self):

       print('Items in Vending Machine \n----------------')

       for item in self.items:

           if item.stock == 0:

               self.items.remove(item)

       for item in self.items:

           print(item.name, item.price)

       print('----------------\n')

   def addCash(self, money):

       self.amount = self.amount + money

   def buyItem(self, item):

       if self.amount < item.price:

           print('You can\'t but this item. Insert more coins.')

       else:

           self.amount -= item.price

           item.buyFromStock()

           print('You chose ' +item.name)

           print('Cash remaining: ' + str(self.amount))

   def containsItem(self, wanted):

       ret = False

       for item in self.items:

           if item.name == wanted:

               ret = True

               break

       return ret

   def getItem(self, wanted):

       ret = None

       for item in self.items:

           if item.name == wanted:

               ret = item

               break

       return ret

   def insertAmountForItem(self, item):

       price = item.price

       while self.amount < price:

               self.amount = self.amount + float(input('insert ' + str(price - self.amount) + ': '))

   def calcRefund(self):

       if self.amount > 0:

           print(self.amount + " refunded.")

           self.amount = 0

       print('Thank you!\n')

def main():

   machine = VendingMachine()

   item1 = Item('Kit Kat',  1.5,  2)

   item2 = Item('Potato Chips', 1.75,  1)

   item3 = Item('Snickers',  2.0,  3)

   item4 = Item('Gum',  0.50, 1)

   item5 = Item('Doritos',0.75,  3)

   machine.addItem(item1)

   machine.addItem(item2)

   machine.addItem(item3)

   machine.addItem(item4)

   machine.addItem(item5)

   print('Welcome!\n----------------')

   continueBuying = True

   while continueBuying == True:

       machine.showItems()

       selected = input('select item: ')

       if machine.containsItem(selected):

           item = machine.getItem(selected)

           machine.insertAmountForItem(item)

           machine.buyItem(item)

           a = input('buy something else? (y/n): ')

           if a == 'n':

               continueBuying = False

               machine.calcRefund()

           else:

               continue

       else:

           print('Item not available. Select another item.')

           continue

if __name__ == "__main__":

   main()

You might be interested in
LDAP is an industry standard employed by Microsoft, which enables IT departments to use a(n) __________ structure when creating
olchik [2.2K]

Complete Question:

LDAP is an industry standard employed by Microsoft, which enables IT departments to use a(n) __________ structure when creating user accounts and user groups.

(a)directory tree

(b)Organizational Unit (OU)

(c)forest

(d)file system

Answer:

(a) directory tree structure

Explanation:

Lightweight Directory Access Protocol (LDAP) is a special type of Directory Access Protocol (DAP) and it is a software protocol that allows the storage and retrieval of data objects (such as user accounts and user groups) that are arranged in an hierarchical directory structure. This hierarchical directory structure is called directory tree or directory information tree.

LDAP stores users and resources information of an organization. These information include usernames, passwords, email, human resource data e.t.c

5 0
3 years ago
Please help will give brainliest
ludmilkaskok [199]

Answer:

waterfall- google search

Explanation:

5 0
3 years ago
(asking again because point-hogs exist)
yawa3891 [41]

The answer is 2-to-the-power-of-n, since for every input, the number of different combinations doubles. From your list I think answer A is meant to indicate 2ⁿ.

6 0
3 years ago
which of the following are used on cable trays to protect the cable insulation from direct sunlight? a. barrier strips b. solid
laila [671]
The answer is barrier strips
7 0
3 years ago
How do you create a reference page in apa format with all websites?
Gre4nikov [31]
Use Cite This For Me's APA citation generator to create a reference page in APA format with all websites.
6 0
3 years ago
Other questions:
  • If you turn off system protection on a disk, windows ____ the restore points that are on your computer.
    13·1 answer
  • What panel in the unity Editor shows the objects in the scene
    11·1 answer
  • 1.2 Discuss each of the following terms: (a) data (b) database (c) database management system (d) database application program (
    12·1 answer
  • a. Do you think the U.S. government should censor information on the Web, such as instructions for making weapons, to protect th
    12·1 answer
  • MARKETING HELP PLEASE?!?!?
    15·1 answer
  • _____ creates a border or space that separates information.
    14·1 answer
  • Pen registers and trap-and-trace devices are not considered forms of searches and do not need probable cause and a court order b
    10·1 answer
  • A studio camera is generally small and lightweight enough to be taken out into the
    11·1 answer
  • Es costoso construir un robot
    6·1 answer
  • Not every design choice in your game interface requires having a thought process behind it.
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!