Shopping Spree

Write a program that allows a user to enter the number of items they have bought on a shopping trip. The program should then ask the price for each of those items and add each price to the total. Finally, the program should state how much they have spent.

How many items did you buy? 4
Enter the price of item £75.99
Enter the price of item £19.99
Enter the price of item £25
Enter the price of item £21.97
The total amount spent is £ 142.95
SET total TO 0

OUTPUT "How many items did you buy?"
RECEIVE items FROM KEYBOARD

FOR counter FROM 1 TO items DO
    RECEIVE price FROM KEYBOARD
    SET total TO total + price
END FOR

OUTPUT "The total amount spent is £", total

total = 0

items = int(input("How many items did you buy? "))

for i in range(items):
    price = float(input("Enter the price of item £"))
    total = total + price

print("The total amount spent is £", total)
# Set total to 0
total = 0

# Get how many items were bought from the user
items = int(input("How many items did you buy? "))

# Loop for the number of items
for i in range(items):
    # Get the price of each item
    price = float(input("Enter the price of item £"))
    # Add each price to the total
    total = total + price

# Display the total to the user
print("The total amount spent is £", total)

Extension

Extend the program to ask the user what their budget was at the start of the program. The program should then calculate if they had enough to buy the items or not, and display the answer to the user.

What was your shopping budget? £150
How many items did you buy? 4
Enter the price of item £75.99
Enter the price of item £19.99
Enter the price of item £25
Enter the price of item £21.97
The total amount spent is £ 142.95
You had enough to buy everything.
What was your shopping budget? £100
How many items did you buy? 4
Enter the price of item £75.99
Enter the price of item £19.99
Enter the price of item £25
Enter the price of item £21.97
The total amount spent is £ 142.95
You shouldn't have been able to afford that...

Target

You should be able to use For Loops to solve a problem.