Question

In: Computer Science

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

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 in items:

            if item.get('stock') == 0:

                items.remove(item)

        for item in items:

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

        selected = input('select item: ')

        for key in items:

            if selected == key.get('key'):

                selected = key

                price = selected.get('price')

                while cim < price:

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

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

                selected['stock'] -= 1

                cim -= price

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

                if cim != 0:

                    print("credit: $0.00")

                    break

                else:

                    continue   

    show(items)

vend()

instead of showing the items can you make it so the user has to input "items"

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

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

and can you make it possible for the user to restock something

Solutions

Expert Solution

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 the whole code ,because, it is hard to complete the code with this requirements.

Foe example, if you want to read the item, the code should bu as follows.

def vend():
    items = []
    item = ["choc",1.50,2] # in the order [item name , price , stock]
    items.append(item)
    for item in items:
        if item[-1] == 0:
            items.remove(item)
    cim = 0
    ITEM = input("Enter the item name : ")
    flag = False
    for item in items:
        if ITEM == item[0]: # if the item already exists,then reduce the stock
            items[-1] -= 1 # reduce the stock 
            flag = True
            temp = [item[0],item[1],item[2]]
            break
    if not flag:
        temp = [ITEM , input("Enter the price :"), 1]
        items.extend(temp)
vend()

Some more information is required.

Just look at the comment section.....


Related Solutions

def vend():     a = {'key':'0','item': 'chips', 'price': 1.50, 'stock': 6}     b = {'key':'1','item': 'cereal',...
def vend():     a = {'key':'0','item': 'chips', 'price': 1.50, 'stock': 6}     b = {'key':'1','item': 'cereal', 'price': 1.25, 'stock': 10}     c = {'key':'2','item': 'pop', 'price': 1.75, 'stock': 12}     d = {'key':'3','item': 'apple', 'price': 2.50, 'stock': 6}     e = {'key':'4','item': 'orange', 'price': 1.95, 'stock': 10}     items = [a, b, c, d, e]     credit = 0 # cash in machine # show items, prices def show(items):     while True:             s = input("> ")             if s...
def hiCount(iterable): rtnVal = 0 most = '' for item in iterable: num = iterable.count(item) if...
def hiCount(iterable): rtnVal = 0 most = '' for item in iterable: num = iterable.count(item) if num > rtnVal: most = item rtnVal = num return tuple(most, rtnVal) lyric = "you don't own me" print(hiCount(lyric)) does all the for then the return Python
1) The price of DEF Corp. stock is $50 per share and the call option on...
1) The price of DEF Corp. stock is $50 per share and the call option on the stock has a price of $10 and an exercise price of $45, with a time to maturity of one year. Assume the risk-free rate is 6%. (5 pts.) a. What is the price of a put option on the same stock with the same exercise price and maturity?   b. If the volatility of the stock is 20% during the year, use the two-state...
def annoying_factorial(n): if n == 0 or n == 1: return 1 if n == 2:...
def annoying_factorial(n): if n == 0 or n == 1: return 1 if n == 2: return 2 if n == 3: return 6 if n == 4: return 4 * annoying_factorial(3) if n == 5: return 5 * annoying_factorial(4) if n == 6: return 6 * annoying_factorial(5) else: return n * annoying_factorial(n-1) def annoying_fibonacci(n): if n==0: return 0 if n==1: return 1 if n==2: return 1 if n==3: return 2 if n==4: return annoying_fibonacci(4-1)+annoying_fibonacci(4-2) if n==5: return annoying_fibonacci(5-1)+annoying_fibonacci(5-2) if...
Matrix: Ax b [2 1 0 0 0 | 100] [1 1 -1 0 -1 |...
Matrix: Ax b [2 1 0 0 0 | 100] [1 1 -1 0 -1 | 0] [-1 0 1 0 1 | 50] [0 -1 0 1 1 | 120] [0 1 1 -1 1 | 0] Problem 5 Compute the solution to the original system of equations by transforming y into x, i.e., compute x = inv(U)y. Solution: %code I have not Idea how to do this. Please HELP!
def annoying_valley(n): if n == 0: print() elif n == 1: print("*") elif n == 2:...
def annoying_valley(n): if n == 0: print() elif n == 1: print("*") elif n == 2: print("./") print("*") print(".\\") elif n == 3: print("../") print("./") print("*") print(".\\") print("..\\") elif n == 4: print(".../") annoying_valley(3) print("...\\") elif n == 5: print("..../") annoying_valley(4) print("....\\") elif n == 6: print("...../") annoying_valley(5) print(".....\\") else: print("." * (n - 1) + "/") annoying_valley(n - 1) print("." * (n - 1) + "\\") def annoying_int_sequence(n): if n == 0: return [] elif n == 1: return...
EXPLAIN ANS PLEASE: PYTHON 1. s = 'abc' print(s[0:] + s[-2:2] + s[:1]) 2. def mirrorOnWheels(s):...
EXPLAIN ANS PLEASE: PYTHON 1. s = 'abc' print(s[0:] + s[-2:2] + s[:1]) 2. def mirrorOnWheels(s): prev = 0 for current in range(1, len(s) - 1): prev = current - 1 next = current + 1 if s[prev] == s[next]: break else: continue return 0 return prev s = 'Good decision!' print(mirrorOnWheels(s)) 3. mixture = {1:[1, 2, 0], 2:[2, 0, 1], 0:[0, 1, 2]} print(mixture[2][2]) 4. noOddHeroes = [] heroes = ['superman', 'batman', 'aquaman'] for hero in heroes: if len(hero)...
for square matrices A and B show that [A,B]=0 then [A^2,B]=0
for square matrices A and B show that [A,B]=0 then [A^2,B]=0
Given the following information, Economy Probability of Economy Stock A Stock B Recession 0.5 -2% 0%...
Given the following information, Economy Probability of Economy Stock A Stock B Recession 0.5 -2% 0% Neutral 0.2 0% 1% Boom ? 20% 5% a) What are the expected returns for stock A and B, respectively? b) What is the standard deviation/risk for stock A? List the formula and input the number, no calculation needed. c) What is the portfolio return given that you have $10,000 and allocate $3,000 in stock A and the rest in stock B? List the...
0. 0. 0. 0.0. 0. 0. 0. 0. 1. 1. 1. 1. 1. 1. 2. 2. 2. 3. 4.
0. 0. 0. 0.0. 0. 0. 0. 0.   1. 1. 1. 1. 1. 1. 2. 2. 2. 3.   4. A.)MEAN – B.)MEDIAN - C.)MODE - D.)STANDARD DEVIATION – E.)5 NUMBER SUMMARY – F.)BOX AND WHISKERS PLOT – G.) OUTLIERS-
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT