Discount
A shop gives people a £5 discount when they spend £25 or more.
Write a program that allows the user to enter how many items they have bought. The program should then allow the user to enter the price for each item, as well as the quantity of each item. After each item is entered, the value of the spend should be added to the total. Once all of the items have been added, the total should be checked to see if the discount can be applied. If it can, then the total should be reduced by 5. Finally, the total price should be displayed to the user.
How many different items did you buy? 3 Enter the price of item £4.99 Enter the quantity of this item: 3 Enter the price of item £2.00 Enter the quantity of this item: 5 Enter the price of item £6 Enter the quantity of this item: 1 Discount applied: £5 off The final total is £ 25.97
SET total TO 0
OUTPUT "How many different items did you buy?"
RECEIVE items FROM KEYBOARD
FOR counter FROM 1 TO items DO
RECEIVE price FROM KEYBOARD
RECEIVE quantity FROM KEYBOARD
SET total TO total + (price * quantity)
END FOR
IF total >= 25 THEN
OUTPUT "Discount applied: £5 off"
SET total TO total - 5
END IF
OUTPUT "The final total is £", total
total = 0
items = int(input("How many different items did you buy? "))
for i in range(items):
price = float(input("Enter the price of item £"))
quantity = int(input("Enter the quantity of this item: "))
total = total + (price * quantity)
if total >= 25:
print("Discount applied: £5 off")
total = total - 5
print("The final total is £", total)
# Set total to 0
total = 0
# Get number of items from user
items = int(input("How many different items did you buy? "))
# Repeat for the number of items
for i in range(items):
# Get the price of each item from the user
price = float(input("Enter the price of item £"))
# Get the quantity of each item from the user
quantity = int(input("Enter the quantity of this item: "))
# Add the price of each item multiplied by quantity to the total
total = total + (price * quantity)
# If the total is more than 25 apply the discount
if total >= 25:
print("Discount applied: £5 off")
total = total - 5
# Display the final price
print("The final total is £", total)
Extension
Extend the program to also provide a £5 discount for purchases of £25 or more, and a £10 discount for purchases of £50 or more. Only one discount can be applied per purchase.
How many different items did you buy? 5 Enter the price of item £7.99 Enter the quantity of this item: 3 Enter the price of item £10 Enter the quantity of this item: 3 Enter the price of item £25 Enter the quantity of this item: 1 Enter the price of item £2.99 Enter the quantity of this item: 1 Enter the price of item £0.79 Enter the quantity of this item: 3 Discount applied: £10 off The final total is £ 74.33