Question

In: Computer Science

You are off to shopping and need a program that allows you to enter the names...

You are off to shopping and need a program that allows you to enter the names of items, their price and quantities. Here is what a sample run should look like (with the keyboard input shown in italics) ...

    Enter item information ("exit" to exit)
    item 1: chips
    price: 3.5
    quantity: 2
    Enter item information ("exit" to exit)
    item 2: red wine
    price : 15.0
    quantity : 1
    Enter item information ("exit" to exit)
    item 3 : steaks
    price : 15.0
    quantity : 2
        
    Your list:
    steaks               2    $30
    red wine             1    $15
    chips                2    $7
    -----------------------------
    Total                     $52

You must use PYTHON.

Solutions

Expert Solution

Code

import operator
i=1
l=[]
while(True):
        print('Enter item information ("exit" to exit)')
        m=[]
        print("item",str(i)+':',end=' ')
        item=input()
        if(item=='exit'):
                break
        print('price :',end='')
        price=float(input())
        print('quantity: ',end='')
        quantity=int(input())
        m.append(item)
        m.append(quantity)
        tot_price=int(quantity*price)
        m.append(tot_price)
        l.append(m)
        i=i+1
n=sorted(l, key=operator.itemgetter(2))
print()
print('Your list:')
total=0
for i in n:
        print(i[0],'      ',i[1],'   $'+str(i[2]))
        total+=i[2]
for i in range(29):
        print('_',end='')
print()
print('Total \t','        $'+str(total))

Terminal Work

.


Related Solutions

C++ Vector Write a program that allows the user to enter the last names of the...
C++ Vector Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name more than once and assume that two or more candidates receive the same number of votes. Your program should output the...
Using Pseudocode: Design a program that allows the user to enter 20 names into a String...
Using Pseudocode: Design a program that allows the user to enter 20 names into a String array. Sort the array in ascending (alphabetical) order and display its contents.
Write a C++ program using dynamic arrays that allows the user to enter the last names...
Write a C++ program using dynamic arrays that allows the user to enter the last names of the candidates in a local election and the number of votes received by each candidate. The program must ask the user for the number of candidates and then create the appropriate arrays to hold the data. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should...
Write an application that allows a user to enter the names and birthdates of up to...
Write an application that allows a user to enter the names and birthdates of up to 10 friends. Continue to prompt the user for names and birthdates until the user enters the sentinel value ZZZ for a name or has entered 10 names, whichever comes first. When the user is finished entering names, produce a count of how many names were entered, and then display the names. In a loop, continuously ask the user to type one of the names...
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
USING PYTHON. Thank you in advance Write a program that allows the user to enter a...
USING PYTHON. Thank you in advance Write a program that allows the user to enter a series of string values into a list. When the user enters the string ‘done’, stop prompting for values. Once the user is done entering strings, create a new list containing a palindrome by combining the original list with the content of the original list in a reversed order. Sample interaction: Enter string: My Enter string: name Enter string: is Enter string: Sue Enter string:...
Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm
Write a program that runs on SPIM that allows the user to enter the number of...
Write a program that runs on SPIM that allows the user to enter the number of hours, minutes and seconds and then prints out the total time in seconds. Name the source code file “seconds.asm Explain step by step
Using RAPTOR create a program that allows the user to input a list of first names...
Using RAPTOR create a program that allows the user to input a list of first names in on array and last names into a parallel array. Input should be terminated when the user enters a sentinel character. the output should be a list of email address where the address is of the following form: [email protected]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT