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
Pros and cons of using the internet
MAVERICK [17]
It is easy to find information, but it is not always right.
7 0
3 years ago
Read 2 more answers
What symbol indicates that material has been copyrighted?
polet [3.4K]

Answer:

Ermmmmmm...

I Think if a thing doesn't hhave a trademark or something like that.

Explanation:

Up there

3 0
3 years ago
Read 2 more answers
Find a quote that you like. Store the quote in a variable, with an appropriate introduction such as "Ken Thompson once said, 'On
pishuonlain [190]

Answer:

The program to this question as follows:

Program:

quote="You can always edit a bad page. You can’t edit a blank page."

name="Jodi Picoult"

print("Quote:\n",quote)

print ('\t\t\t\t\t\t\t',"Author name-", name)

Output:

Quote:

You can always edit a bad page. You can’t edit a blank page.

       Author name- Jodi Picoult

Explanation:

In the above python code, two variable "quote and name" is defined, in which variable both variable holds some string value.

  • In the next line, the print function is defined, that first print "Quote" as a message, and for line breaking "\n" is used, then print quote variable value.
  • In the last step, first, we use "\t" for line spacing then message "Author name-", and then name variable value.
7 0
3 years ago
A computer uses a memory unit with 256k words of 32 bits each. A bina.ry
iogann1982 [59]

Answer:

Touch and hold a clip to pin it. Unpinned clips will be deleted after 1 hour.

4 0
3 years ago
What are the documents involved in E payment​
trapecia [35]

Answer:

Registration, Placing an order, and, Payment.

Explanation:

4 0
3 years ago
Other questions:
  • What is the basic unit for storing data in exel
    13·1 answer
  • Which statement about the Paste Link option is true?
    6·1 answer
  • How to import any csv from internet in phyton 3 and R ?
    12·1 answer
  • After a user creates a new query or edits an existing query they must ________ the query to display the corresponding results.
    12·1 answer
  • Which of these consoles have 64 bit architecture
    13·1 answer
  • Your program is going to compare the distinct salaries of two individuals for the last 5 years. If the salary for the two indivi
    15·1 answer
  • SUWIDHA stands for .​
    12·1 answer
  • Please dont delete. my teacher said to see how many people I could meet on here. THIS IS A BIG PART OF MY GRADE!! DO NOT REPORT!
    13·2 answers
  • If anyone wants to ft heres the link
    6·1 answer
  • The theory of plate tectonics evolved from previous theories and concepts put forward by several scientists before its conceptio
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!