Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
point = (3, 4). A student writes point[0] = 10 and the program stops. Why? How do you get the point (10, 4)?
To change a tuple, build a new one.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
A tuple is fixed. We cannot replace an item inside it, so Python stops with a TypeError.
The way out. Make a new tuple: new_point = (10, point[1]). The old point is still (3, 4).
Log in to join the discussion.
Loading…