71.3k views
3 votes
Write a program to implement the algorithm that you designed in Exercise 21 of Chapter 1. Your program should allow the user to buy as many items as the user desires.

Reference:

The number in parentheses at the end of an exercise refers to the learning objective listed at the beginning of the chapter.

Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling is free; otherwise, the shipping and handling is $10 per item. Design an algorithm that prompts Jason to enter the number of items ordered and the price of each item. The algorithm then outputs the total billing amount. Your algorithm must use a loop (repetition structure) to get the price of each item. (For simplicity, you may assume that Jason orders no more than five items at a time.) (9)

1 Answer

0 votes

Answer:

total = 0

items = int(input("Enter the number of items ordered: "))

for i in range(items):

price = float(input("Enter the price of item " + str(i+1) + ": "))

total += price

if total < 200:

total += (items * 10)

print("Bill is $" + str(total))

Step-by-step explanation:

*The code is in Python.

Ask the user to enter the number of items ordered

Create a for loop that iterates depending on the number of items ordered. Inside the loop, ask the price of each item and add it to the total

After the loop, check the total. If it is smaller than 200, add 10 for each item to the total

Print the total

User Pedrobisp
by
4.6k points