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...
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 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]
Design the logic for a program that allows a user to enter 20 numbers, then displays...
Design the logic for a program that allows a user to enter 20 numbers, then displays them in the reverse order of entry. Design the logic for a program that allows a user to enter 20 numbers, then displays each number and its difference from the numeric average of the numbers entered. The program is C++. I need a Pseudocode
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. 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 also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
In Python, write a program that allows the user to enter a number between 1-5 and...
In Python, write a program that allows the user to enter a number between 1-5 and returns the vitamins benefits based on what the user entered. The program should: Continue to run until the user quits and Validate the user’s input (the only acceptable input is 0, 1, 2, 3, 4, or 5), If the user enters zero “0” the program should terminate You can use the following facts: 1- Vitamin A protects eyes from night blindness and age-related decline...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT