1. Worth your while.
Run the following program and investigate how the output relates to the code. Then, experiment with changing each number in the code and observing how the output is affected.
2. Does it matter?
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.
- Delete the first line of code.
- On the third line, replace
whilewithWhile. - Remove the colon (:) from the third line.
- Remove the indentation from the fourth line.
- Remove the indentation from the fifth line.
3. Please hold for the operator.
Reset the program above and then replace x < 10 with x <= 10. How does this change affect the program’s output?
Comparison operators, such as < and <= , are used to compare two values. Click the following button to see a list of Python’s comparison operators.
4. Away we go.
An object starts 21 cm from the wall and moves 2.4 cm away every second. The following program displays the object’s distance each second until it passes a distance of 300 cm from the wall. Study the program to understand how it works and then run it to see approximately how long it takes for the object to reach a distance of 300 cm from the wall.
5. Further and finer.
Edit the program above so that the values are displayed every half-second until it passes a distance of 1 m from the wall. Approximately how long does it take the object to pass the 1 m mark? Could you figure it out without using a computer program?
6. Ernesta's earnings.
Ernesta deposited $500 into an account that earns interest (2% per year, compounded annually). She created the following Python program to display how the amount in the account will grow until it reaches $1000. Examine and run this program to understand how it works.
7. Who wants to be a millionaire?
Edit the program above to determine how long it will take the amount to reach one million dollars. How would you solve this problem without a computer program? Is it tougher than problem #5 above? Does this problem illustrate the value of coding?
⚠️ Extra challenge: Edit the program above such that it prompts the user to specify the target amount.
8. Waiting for a while...
A infinite loop is a loop that never stops running. In some cases, an infinite loop can be problematic, causing system freezes, loss of work, and other performance/stability issues. The following program is an example of an infinite loop. Examine the code to see why an infinite loop occurs and then run the program to see what happens. (It’s safe to run this program! Use the Stop button to end it.)
9. Revisiting.
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. Write and test a program that makes effective use of a while loop to determine how long it takes the phone to hit the ground.