Students can try following practice first:
2 x 3 = 6, formatted neatly.Output example 1:
1x1= 1
1x2= 2 2x2= 4
1x3= 3 2x3= 6 3x3= 9
...
1x9= 9 2x9=18 3x9=27 ... 9x9=81
Output example 2:
Guess the number (1–20)
Your guess: 10
Too high! Try again.
Your guess: 6
Too low! Try again.
Your guess: 8
You got it in 3 tries!
Answer example 1:
for i in range(1, 10):
for j in range(1, i + 1):
print(f"{j}x{i}={i*j:2}", end="t")
print()
Answer example 2:
import random
secret = random.randint(1, 20)
tries = 0
guess = 0
print("Guess the number (1–20)")
while guess != secret:
guess = int(input("Your guess: "))
tries += 1
if guess > secret:
print("Too high! Try again.")
elif guess < secret:
print("Too low! Try again.")
else:
print(f"You got it in {tries} tries!")
Through these tasks, we learned how to make programs truly dynamic which is able to decide, repeat, and calculate automatically. In the next unit, we’ll teach our programs to ‘remember’ data using lists!