Unit 3 Task 7 - Solution

Learn to code with step-by-step lessons. A place for students to work through programming fundamentals and build skills.

Solution - Task 7: Cheapest item index

← Back to task


One possible program:

prices = []

for slot in range(5):
    price = float(input("Price " + str(slot + 1) + ": "))
    prices.append(price)

best_index = 0
for index in range(1, len(prices)):
    if prices[index] < prices[best_index]:
        best_index = index

print("Cheapest item is number", best_index + 1, "at price", prices[best_index])