Fix One Price Tag

Python FundamentalsEasy+10 XP+10

Fix One Price Tag

A shop keeps its prices in a list. One price was typed in wrong.

Task: write fix_price(prices, position, new_price) that puts new_price into the box at position, then returns the list.

  • Change the real list in place, then return that same list.
  • position is always a valid position, and may be negative (-1 is the last price).

Examples

prices = [4, 9, 12, 7]
position = 1
new_price = 10
returns [4, 10, 12, 7]
prices = [4, 9, 12, 7]
position = 0
new_price = 5
returns [5, 9, 12, 7]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run