Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help for the flow chart for this code it has 2 classes class Item: def __init__(self, name, price, stock): self.name = name self.price

I need help for the flow chart for this code" it has 2 classes

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 available ***************')

for item in self.items:

if item.stock == 0:

self.items.remove(item)

for item in self.items:

print(item.name, item.price)

print('*************** ')

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 got ' +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 checkRefund(self):

if self.amount > 0:

print(self.amount + " refunded.")

self.amount = 0

print('Bye.Thank you! ') ###Message in the end.

def vend():

machine = VendingMachine()

item1 = Item('choc', 1.5, 2)

item2 = Item('pop', 1.75, 1)

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

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

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

machine.addItem(item1)

machine.addItem(item2)

machine.addItem(item3)

machine.addItem(item4)

machine.addItem(item5)

print('Welcome to the vending machine! ***************')

continueToBuy = True

while continueToBuy == 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':

continueToBuy = False

machine.checkRefund()

else:

continue ### Start from beginning after yes

else:

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

continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions