TalentJR

🐍 Python for kids · Class 6 · Lesson 6 of 18 · Free

Logic Projects – Games and Puzzles

⏱ About 40 minutes · ▶ run real Python here — nothing to install · no sign-in

In this lesson you will

  • Combine if, and, or and loops to solve real puzzles like leap years and primes.
  • Build a quiz and a guessing game that keep score.
  • Plan a project step by step before you write the code.

You now know if, comparisons, while loops, for loops and nested loops. Alone, each is a single tool. Together, they build real programs: quizzes, games and puzzle solvers. Today you will build six of them.

How do I check a leap year in Python?

A year is a leap year if it divides by 4. But century years, like 1900, must also divide by 400.

So 2024 and 2000 are leap years, but 1900 is not. That rule needs and, or and not together.

Brackets make the logic clear. Python works them out first, just like in maths.

🎬 How Python thinks — step 1 of 14Python is about to run line 1
▶for year in [2024, 1900, 2000, 2026]:
2 if year % 4 == 0 and (year % 100 != 0 or year % 400 == 0):
3 print(year, "is a leap year")
4 else:
5 print(year, "is not a leap year")
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
2024 is a leap year
1900 is not a leap year
2000 is a leap year
2026 is not a leap year

How do I check if a number is prime in Python?

A prime number has exactly two factors: 1 and itself. So 7 is prime, but 21 is not, because 3 x 7 = 21.

We try every divisor from 2 upwards. If one divides exactly, the number is not prime, and we break.

A flag variable, is_prime, remembers the answer. It starts True and flips to False if we find a factor.

🎬 How Python thinks — step 1 of 11Python is about to run line 1
▶n = 21
2is_prime = n > 1
3for d in range(2, n):
4 if n % d == 0:
5 print(n, "divides by", d)
6 is_prime = False
7 break
8print("Prime?", is_prime)
📦 Variables (memory boxes)

No variables yet.

🖥️ Output
▌
✏️ Change this code and run it yourself
🐍 Python — you can edit this code
Output
21 divides by 3
Prime? False

💡 Try n = 29. The loop checks every divisor, finds none, and is_prime stays True.

How do I make a quiz with a score in Python?

Keep the questions in one list and the answers in another. The same position links a question to its answer.

A for loop asks each question. A score variable goes up by 1 for each right answer.

At the end, we turn the score into a percentage and give a message.

🐍 Python — you can edit this code
Output
Capital of Kerala? Thiruvananthapuram
Correct!
7 x 8 = ? 54
Oops! The answer is 56
Largest planet? Jupiter
Correct!
Score: 2/3 (66%)

💡 .strip() removes extra spaces and .lower() removes capitals, so fair answers are not marked wrong.

What is FizzBuzz and how do I code it?

FizzBuzz is a famous coding puzzle. Count up, but say Fizz for multiples of 3 and Buzz for multiples of 5.

Numbers that divide by both 3 and 5 say FizzBuzz. So that check must come first.

If it came later, 15 would stop at the Fizz check and never reach FizzBuzz.

🐍 Python — you can edit this code
Output
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz

How do I make a number guessing game in Python?

The random module can pick a secret number for us. random.randint(1, 10) gives any whole number from 1 to 10.

The player gets three tries. A for loop counts the tries, and break ends the game early on a win.

The else on the for loop runs only if the loop was never broken. That means all tries were used up.

🐍 Python — you can edit this code
Output
Guess (1-10): 5
You win in 1 tries!

💡 The secret is random, so the output changes every run. Press Run a few times and compare.

How do I make a menu program with a loop?

Many apps show a menu again and again until you choose Exit. while True with break does this nicely.

Each choice is handled by one branch of an if-elif chain. A final else catches wrong choices.

Here is a tiny school canteen. It adds up the bill until the student picks 0.

🐍 Python — you can edit this code
Output
1 Samosa Rs 15 | 2 Idli Rs 30 | 0 Pay: 1
Bill so far: 15
1 Samosa Rs 15 | 2 Idli Rs 30 | 0 Pay: 2
Bill so far: 45
1 Samosa Rs 15 | 2 Idli Rs 30 | 0 Pay: 5
Please type 1, 2 or 0.
Bill so far: 45
1 Samosa Rs 15 | 2 Idli Rs 30 | 0 Pay: 1
Bill so far: 60
1 Samosa Rs 15 | 2 Idli Rs 30 | 0 Pay: 0
Please pay 60 rupees. Thank you!

🤔 Predict the output

Think like Python: read the code and choose what it prints. You get the reason straight away.

Question 1. What does this print?

for n in [9, 10, 15]:
    if n % 3 == 0 and n % 5 == 0:
        print("FizzBuzz")
    elif n % 3 == 0:
        print("Fizz")
    elif n % 5 == 0:
        print("Buzz")

Question 2. What does this print?

year = 1900
print(year % 4 == 0 and (year % 100 != 0 or year % 400 == 0))

Question 3. What does this print?

found = False
for d in range(2, 9):
    if 9 % d == 0:
        found = True
        print(d)
        break
print(found)

🧩 Your challenge

Rock, Paper, Scissors – 3 rounds! The computer's moves are fixed in a list. Ask the player for a move each round. Rock beats scissors, scissors beats paper, and paper beats rock. Print who won each round and the final score.

Expected output (with the inputs given):
rock, paper or scissors? paper
You win! The computer chose rock
rock, paper or scissors? rock
Computer wins! It chose paper
rock, paper or scissors? rock
You win! The computer chose scissors
Final score - You: 2, Computer: 1
🐍 Python — you can edit this code

⚠️ Common mistakes (and how to fix them)

❌ Wrong

for n in range(1, 16):
    if n % 3 == 0:
        print("Fizz")
    elif n % 5 == 0:
        print("Buzz")
    elif n % 3 == 0 and n % 5 == 0:
        print("FizzBuzz")
    else:
        print(n)

No error message – but 15 prints Fizz, and FizzBuzz never appears.

✅ Right

for n in range(1, 16):
    if n % 3 == 0 and n % 5 == 0:
        print("FizzBuzz")
    elif n % 3 == 0:
        print("Fizz")
    elif n % 5 == 0:
        print("Buzz")
    else:
        print(n)

In an if-elif chain only the first True branch runs. Put the most specific check first.

❌ Wrong

n = 15
for d in range(2, n):
    if n % d == 0:
        print("Not prime")
    else:
        print("Prime")

No error message – but it prints Prime and Not prime many times for one number.

✅ Right

n = 15
is_prime = True
for d in range(2, n):
    if n % d == 0:
        is_prime = False
        break
print("Prime" if is_prime else "Not prime")

One divisor that fails proves nothing. Use a flag, and decide only after the loop has checked every divisor.

❌ Wrong

score = 0
answer = input("5 + 5 = ? ")
if answer == 10:
    score = score + 1
print("Score:", score)

No error message – but the right answer 10 still gives a score of 0.

✅ Right

score = 0
answer = input("5 + 5 = ? ")
if answer == "10":
    score = score + 1
print("Score:", score)

input() gives the string "10", and a string never equals the number 10. Compare with "10" or use int().

📌 Remember

  • Big programs are built from small pieces: if, comparisons and loops.
  • Brackets keep and/or logic clear, as in the leap year rule.
  • A flag variable remembers a result, and you decide after the loop ends.
  • In an if-elif chain, put the most specific condition first.
  • Parallel lists, a score counter and a loop make a quiz.
  • while True with break makes menus; for with break limits tries in a game.

Finished the quiz and the challenge?

Questions students ask

What are good Python projects for Class 6 students?

Try a quiz with a score, a guessing game or rock paper scissors. A leap year checker or canteen menu also works well. Each one uses if and loops together.

How do I plan a coding project before writing code?

Write the steps in plain English first. Then decide what to store in variables, what to repeat, and which decisions to make.

What does else after a for loop mean in Python?

It runs when the loop finishes all its rounds without a break. It is handy for messages like "out of tries".

Why does my guessing game give a different answer each time?

random.randint() picks a new secret on every run. For testing, set the secret to a fixed number first.