Teaching Rafi Python
I'm Jannat. My brother Rafi is 12 and wanted to "make a game". He's too young for his own account, so he sits next to me, his files live in ~jannat/rafi, and we do 30 minutes after his homework. This is the log.
- day 1print("hello"). He typed it with one finger and grinned for five minutes.
- day 3Variables. He named every one of them after cricketers.
- day 6if/else. A "how old are you" program. He set the cut-off for "old" at 25.
- day 9Loops. A multiplication table up to 20, because his school stops at 10.
- day 14His first real program, below. He showed it to our whole family at dinner.
Day 14: সংখ্যা ধরো
import random
number = random.randint(1, 50)
tries = 0
print("১ থেকে ৫০ এর মধ্যে একটা সংখ্যা ভেবেছি। ধরো তো!")
while True:
guess = int(input("তোমার অনুমান: "))
tries += 1
if guess < number:
print("আরো বড়!")
elif guess > number:
print("আরো ছোট!")
else:
print(f"ঠিক! {tries} বারে পারলে।")
breakRun it yourself: python3 ~jannat/rafi/guess.py on mukto.net. Next week: lists, and a hangman game with Bangla words.