2.5. Further Practice#

Exercise 2.14

Use a for loop to produce the following output:

  1. 5, 7, 9, 11, 13, 15

  2. 1, 10, 100, 1000, 10000, 100000

  3. 0, 1, 2, 0, 1, 2, 0, 1, 2 (hint: use the % operator)

Exercise 2.15

Look up the predicted daily maximum and minimum temperatures for the next 10 days according to the BBC weather forecast.

https://www.bbc.co.uk/weather/2643743

Create two arrays containing the maximum and minimum temperatures and plot them as two separate lines on a line graph, including axis labels and title. Look up how to add a legend in the Matplotlib documentation.

../_images/temperatures.png

Exercise 2.16

Adapt your solution to the cannonball problem to incorporate air resistance. Assume that at each time step the x- and y-velocities each reduce by a fixed fraction \(d\) (so that the velocity equations become \(u_{i+1} = u_i - du_i\) and \(v_{i+1} = v_i - g\Delta t - dv_i\)).

For a given \(d\), what value of \(\theta\) maximises the distance travelled by the cannonball?