Minu's Games logo
MINU'S ROBOTICS

A Minu's Games EdTech Lab

← Code & Cognition
Day 14 of 30Logic & Data Structures

🤖Function Power & Project

🎯 Today's objective

Use parameters, defaults, scope — then build a guessing bot.

📖 Key concepts

  • Default params: def f(x, step=1)
  • Multiple returns via tuples
  • Local vs global scope
  • random module: randint()

💻 Try this code

import random
secret = random.randint(1, 20)

def check(guess):
    if guess == secret: return "correct"
    return "higher" if guess < secret else "lower"

print(check(10))

👥 Learn it your way

🧒 Young Explorers

Combine everything: loops + ifs + functions = a real little game!

Your task

Finish the number game: loop until the player guesses the secret, counting tries.

💼 Professionals

Understand scope and pure functions; isolate randomness for testability (seed it).

Your task

Add difficulty levels (range + max tries) and return a result dict {won, tries}.

🤖 AI connection

This guessing bot uses feedback ("higher/lower") to improve its next guess — a tiny taste of how learning systems use signals to get better.

★ Week 2 Project — Number-Guessing Bot

Build a two-way game: (1) human guesses the computer’s number, and (2) the computer guesses the human’s number using a smart "binary search" strategy. Compare how many guesses each takes. Pro stretch: log stats across rounds.

✅ Quick check

What does random.randint(1,6) simulate?

A dice roll (1–6 inclusive).

What is a default parameter?

A value used when the caller omits that argument.