def vend():     a = {'key': '0', 'item': 'choc', 'price': 1.50, 'stock': (2)}     b = {'key': '1', 'item': 'pop',...

70.2K

Verified Solution

Question

Programming

def vend():

    a = {'key': '0', 'item': 'choc','price': 1.50, 'stock': (2)}

    b = {'key': '1', 'item': 'pop', 'price':1.75, 'stock': 1}

    c = {'key': '2', 'item': 'chips','price': 2.00, 'stock': 3}

    d = {'key': '3', 'item': 'gum', 'price':0.50, 'stock': 1}

    e = {'key': '4', 'item': 'mints','price': 0.75, 'stock': 3}

    items = [a, b, c, d, e]

    

    def show(items):

        cim = 0

        for item initems:

            ifitem.get('stock') == 0:

                items.remove(item)

        for item initems:

            print(item.get('key'),item.get('item'),item.get('price'), item.get('stock'))

        selected =input('select item: ')

        for key initems:

            ifselected == key.get('key'):

                selected= key

                price= selected.get('price')

                whilecim < price:

                    cim= cim + float(input('insert ' + str(price - cim) + ': '))

                print('vend:' + selected.get('item'))

                selected['stock']-= 1

                cim-= price

                print('refunded:' + str(cim))

                ifcim != 0:

                    print(\"credit:$0.00\")

                    break

                else:

                    continue   

    show(items)

vend()

instead of showing the items can you make it so the user has toinput \"items\"

and instead can you make it so it shows credit everytime youinsert a coin

and instead of insert numbers can you make it you have to typedime to insert .10 and nickel to insert .05 and quarter to insert.25

and can you make it possible for the user to restocksomething

Answer & Explanation Solved by verified expert
3.6 Ratings (504 Votes)
I hope you are the same person who asked this question before I recognize the changes made by me If you need to code these then you need to refactor    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students