In Python 3.7.4Write a program that will compute the total cost of an amazon purchase. The program should ask the user to enter the amount of a purchase, then calculate a 12% shipping and handling fee and NJ sales tax (7%).  Your program should show the itemized bill. A car’s MPG can be calculated using the formula: MPG = MilesDriven / gallons used  Write a program that asks for the type of vehicle, the miles driven and the gallons of gas used.  The program should then label and display the MPG for the type of vehicle.Requirements:The use of descriptive variable names (aka self-documenting code)Output displayed with labels and presented in a neat format (e.g. for money $ dd.cc)

Question
Asked Sep 22, 2019

In Python 3.7.4

Write a program that will compute the total cost of an amazon purchase. The program should ask the user to enter the amount of a purchase, then calculate a 12% shipping and handling fee and NJ sales tax (7%).  Your program should show the itemized bill. 

A car’s MPG can be calculated using the formula: MPG = MilesDriven / gallons used  Write a program that asks for the type of vehicle, the miles driven and the gallons of gas used.  The program should then label and display the MPG for the type of vehicle.

Requirements:

  • The use of descriptive variable names (aka self-documenting code)
  • Output displayed with labels and presented in a neat format (e.g. for money $ dd.cc)
check_circleExpert Solution
Step 1

Program

Since two questions have been given and it is not clear the answer is sought for which question, we are attempting the first one as the space in this answer permits. The self documenting code in python is shown below:

 

#define a function to compute the bill

def computeBill():

    #while loop sentinel

    more = True

    #list holding the product product prices

    #position 0 signifies no product

    productPrices = [0,10,20,30]

    #list holding the product product names

    #position 0 signifies no product

    productNames = ['NA','Biscuits','Bread','Egg']

    #list to hold the billing item lines

    itemLines = []

    #total bill amount

    totalAmount = 0

    #while loop to accept user input until

    #a 0 is entered for product id

    while more:

        #ask user for input

        pid = int(input("Enter the item id:"))

        if pid == 0:

            break

        #get the product price from the list

        price = productPrices[pid]

        #get the product name from the list

        productName = productNames[pid]

        #ask user for input

        q = int(input("Enter the quanity:"))

        #compute item sub total

        amount = price * q

        #update total billing amount

        totalAmount = totalAmount + amount

        #create an item line data structure (python list)

        itemLine = [productName,price, q, amount]

        #append the item line to the list of items in the bill

        itemLines.append(itemLine)

    #display all the item details in the bill

    for x in range(len(itemLines)):

        print ('Item Name:',itemLines[x][0],

            ' - Item Price:',itemLines[x][1],

            ' - Item Quantity:',itemLines[x][2],

            ' - Item Bill Amount:',itemLines[x][3])

    #display the bill total amount    

    print ("Total Bill Amount:$",totalAmount)

#call the compute bill function  

computeBill()

Step 2

Program image

#define a function to compute the bitT
def computeBill ( ) :
#while Loop sentinel
2
more= True
#List holding the product product prices
#position signifies no product
productPrices
#List holding the product product names
#position signifies no product
productNames
#List to hold the billing item Lines
itemLines
6
[,10,20,30]
7
['NA', 'Biscuits', ' Bread','Egg' ]
10
11
12
#total biLL amount
totalAmount = 0
#while Loop to accept user input until
#a 0 is entered for product id
while more:
13
14
15
16
17
#ask user for input
pid
if pid
break
18
int (input("Enter the item id: "))
19
20
0:
21
#get the product price from the List
price =productPrices [pid]
#get the product name from the List
productName
#ask user for input
int(input("Enter the quanity:"))
#compute item sub total
22
23
24
productNames [pid ]
25
26
27
28
price
29
amount
#update total billing amount
totalAmount
30
totalAmotonot + amount
31
#create an item line data structure (py thon List)
item Line
#append the item line to the List of items in the bill
itemLines.append ( item Line)
32
[productName,price, q, amount]
33
1
34
35
NM st
help_outline

Image Transcriptionclose

#define a function to compute the bitT def computeBill ( ) : #while Loop sentinel 2 more= True #List holding the product product prices #position signifies no product productPrices #List holding the product product names #position signifies no product productNames #List to hold the billing item Lines itemLines 6 [,10,20,30] 7 ['NA', 'Biscuits', ' Bread','Egg' ] 10 11 12 #total biLL amount totalAmount = 0 #while Loop to accept user input until #a 0 is entered for product id while more: 13 14 15 16 17 #ask user for input pid if pid break 18 int (input("Enter the item id: ")) 19 20 0: 21 #get the product price from the List price =productPrices [pid] #get the product name from the List productName #ask user for input int(input("Enter the quanity:")) #compute item sub total 22 23 24 productNames [pid ] 25 26 27 28 price 29 amount #update total billing amount totalAmount 30 totalAmotonot + amount 31 #create an item line data structure (py thon List) item Line #append the item line to the List of items in the bill itemLines.append ( item Line) 32 [productName,price, q, amount] 33 1 34 35 NM st

fullscreen
Step 3

Program Image Continued....

#display all the item de tai ls in the bill
36
for x in range (len ( item Lin es) ) :
37
print ('Item Name:',itemLines [x] [0],
Item Price:',itemLines [x] [1],
Item Quantity: ',itemlines [x] [2],
Item Bill Amount : ' , itemLines [x] [3] )
38
39
40
41
#display the bill total amount
print ("Total Bill Amount:$", totalAmount)
#call the compute bill function
computeBill)
42
43
44
45
help_outline

Image Transcriptionclose

#display all the item de tai ls in the bill 36 for x in range (len ( item Lin es) ) : 37 print ('Item Name:',itemLines [x] [0], Item Price:',itemLines [x] [1], Item Quantity: ',itemlines [x] [2], Item Bill Amount : ' , itemLines [x] [3] ) 38 39 40 41 #display the bill total amount print ("Total Bill Amount:$", totalAmount) #call the compute bill function computeBill) 42 43 44 45

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour*

See Solution
*Response times may vary by subject and question
Tagged in

Engineering

Computer Science

Python

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Is BIOS volatile?

A: Volatile memory is the computer memory that maintains its data only when the computer is in power. A...

question_answer

Q: Simplify the following equation using Boolean Identities: ~x~yz  + ~xy~z + x~y~z + x~yz + xy~z + xy...

A: 1)~x~yz + ~xy~z + x~y~z + x~yz + xyz~x~yz + ~xy~z + x~y~z + x~yz + xy~z + xyz( ~x~yz + x~yz ) + ( ~x...

question_answer

Q: Describe a situation in which absolute denial of a service to a user ( that is, the user gets no res...

A: Denial of Service (DoS) :The Denial of Service (DoS) makes a resource (site, application, server) un...

question_answer

Q: Weighted Intervals Problem EXAMPLE:Suppose we have the following weighted intervals. start   finish ...

A: Instructions for solving the problem.Sort the given intervals by finish time, and the intervals with...

question_answer

Q: compare and contrast symmetric encryption with public-key encryption, including the strengths and we...

A: DefinitionEncryptionIn cryptography, encryption is basically a concept related to keys. It is a tech...

question_answer

Q: You are not required to execute the queries. However, your syntax must by accurate.You must give at ...

A: Hey, since there are multiple sub-part questions posted, we will answer first three questions. If yo...

question_answer

Q: what strategies that would attract buyers to a company's e-commerce web site

A: Strategies to attract buyers to the company e-commerce website:Offer limited time specials to new cu...

question_answer

Q: write a program in c++. You work for a box company, and have been asked to write a program to compar...

A: Click to see the answer

question_answer

Q: Hi,  Please,I have a question with Python,I have to create a Loop and terminate BMI calculation flow...

A: The loop of flow chart for BMI is given as: