Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
This program was meant to draw the height of a plant in centimetres over 10 days, but it stops with an error. Find the mistake and fix the program. Add a title and labels with units.
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, go through the solution one step at a time, and check each step against your own.
Plan. Read the error. plt.plot says that x and y must have the same first dimension, with the shapes (11,) and (10,). np.arange(0, 11) has 11 days (0 to 10), and the height has 10 numbers.
The data decides. The plant was measured on 10 days, so the days should be 1 to 10. (If the measurement on day 0 was lost, the height array would need an 11th number, which we do not have.)
Check. Both arrays now have 10 numbers, and the graph is drawn. The plant grew from 2.0 to 10.1 cm in 10 days.
Answer: the two arrays had different lengths, 11 and 10. Use the days 1 to 10.
Log in to join the discussion.
Loading…