1. In the loop.
Run the following program to see what happens! Then, try replacing the 10 with other numbers and study how it affects the output.
2. Sweat the small stuff!
Try making the following changes, one at a time, to the program above and see if it still runs correctly. Be sure to reset the program before applying each modification.
- On the first line, replace
forwithFor. - Remove the colon (:) from the first line.
- Remove the indentation from the second line.
3. Oh, the possibilities!
Investigate each of the following modifications, one at a time, to the program above. Be sure to reset the program before applying each modification.
- Replace
range(10)withrange(10,20) - Replace
range(10)withrange(0, 20, 4) - Replace
print(x)withprint(x**2) - Replace
print(x)withprint(x, x**2)
4. Line up.
Run the following program. What is the output showing us?
5. Turn the tables.
Edit the code in the program above such that the following changes occur:
- The x-values in the output begin at -10 and end at 10, using an increment of 2.
- The output displays the y-values rounded to 1 decimal place.
⚠️ Extra challenge: Make the program prompt the user to enter the starting x-value, the ending x-value, and the increment.
Hint: The numbers in range() must be integers.
6. Your turn.
A student’s cell phone is hurled off a 20-metre cliff. Its height above the ground below, in metres, t seconds after it is launched is modelled by the equation h = -4.9t² + 65t + 20. Create and test a program that shows the phone’s height above the ground every second for 15 seconds after it is thrown.
7. Smashed to smithereens.
If we wanted to determine precisely when the phone in the problem above hits the ground, it would be helpful to use a decimal increment for our time values. Unfortunately, range() does not accept decimal values. Study the following workaround and then edit the code as needed to find exactly when the phone hits the ground.