Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

FOR PYTHON: An online retailer sells five products whose retail prices are as fo

ID: 673411 • Letter: F

Question

FOR PYTHON:

An online retailer sells five products whose retail prices are as follows: Product 1, $ 2.98; product 2, $ 4.50; product 3, $ 9.98; product 4, $ 4.49 and product 5, $ 6.87.

Write an application that reads a series of pairs of numbers as follows:

a) product number

b) quantity sold Your program should use if…elif statement to determine the retail price for each product. Use a function that returns the retail price of the product. It should calculate and display the total value of all products sold.

Use a sentinel- controlled loop to determine when the program should stop looping and display the final results.

Instructions:

a) Price of the product = quantity sold x retail price

b) Total price of all products = sum of individual product prices

c) Use a sentinel controlled while loop to read the product number and quantity sold

d) Flow of logic

a. Read the product id

b. While product id is not equal to -1, perform the following

i. Check whether product id is between 1 and 5. If yes

1. Read the quantity sold

2. Using if…elif statement compute total value and update item count

ii. else (If product is not between 1 and 5)

Prompt the user that product id is incorrect

iii. Prompt the user for next product id

c. End while loop

d. Check whether number of items sold is more than zero. If no

i. Display statement “No items sold”

e. else (if number of items sold is more than zero)

i. Display the output

1. Example: “Total value of 3 products sold is $12.87

Explanation / Answer

product_id=input(" Please enter product ID")
totalprice=0
noOfItemsSold=0
while(product_id!=-1)
if (product_id>=1) and (product_id<=5):
   qty=input("Enter Quantity SOld")
   if(product_id==1):
    price=2.98
   elif(product_id==2):
   price=4.50
   elif(product_id==3):
   price=9.98
   elif(product_id==4):
   price=4.49
   elif(product_id==5):
   price=6.87
   
   totalprice=totalprice+(price*qty)
   noOfItemsSold=noOfItemsSold+qty
else
   prompt("Incoreect Product ID")
   product_id=input(" Please enter product ID")
continue
  
if(noOfItemsSold>0)
print "total value of",noOfItemsSold," products sold is $",totalprice
else print "No Items SOld"