Asking for Guesses
Read the players guess.
Asking for Guesses is a free Coding for Kids lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Coding for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Time to Guess! ❓
Hi game host! 🎤 The computer has a secret number. Now we need to ask the PLAYER for their guess! ❓
Let's learn how to read a guess and check it!
print('What number am I thinking of? 🤔')Ask With input() 🗣️
Remember input()? It asks the player and waits! 🗣️ We save their guess in a box.
guess = input('Take a guess: ')
print('You guessed', guess)Make the Guess a Number 🔢
Since the secret is a number, the guess must be a number too! We wrap it in int(). 🔢
guess = int(input('Take a guess: '))
print('Your number guess is', guess)Compare to the Secret ⚖️
Now check if the guess matches! We use == to compare the guess to the secret. ⚖️
secret = 7
guess = 7
if guess == secret:
print('You got it! 🎉')What if It's Wrong? ❌
If the guess is NOT the secret, we use else to say "try again"! ❌
secret = 7
guess = 4
if guess == secret:
print('Correct! 🎉')
else:
print('Nope, try again! 🔁')Real Guess vs Secret 🎯
Let's combine a random secret with a real player guess! 🎯
import random
secret = random.randint(1, 10)
guess = int(input('Guess 1 to 10: '))
if guess == secret:
print('Amazing! You won! 🏆')
else:
print('The secret was', secret)Many Guesses With a Loop 🔁
One guess isn't much fun! Let's give the player SEVERAL tries using a loop. 🔁
for tries in range(3):
guess = int(input('Guess: '))
print('You guessed', guess)Counting the Tries 🔢
It's nice to tell the player which try they're on! We can print the try number. 🔢
for tries in range(3):
print('Try number', tries + 1)
guess = int(input('Your guess: '))Guess Inside the Loop 🎮
Let's check the guess each time inside the loop! If correct, we celebrate. 🎮
import random
secret = random.randint(1, 10)
for tries in range(3):
guess = int(input('Guess 1-10: '))
if guess == secret:
print('You win! 🎉')Friendly Messages 😊
Always be encouraging! Cheer the player on with friendly messages even when they're wrong. 😊
guess = 5
print('Nice try with', guess, '! Keep going, you can do it! 💪')Guess Getter Pro! 🚀
Now you can ask players for guesses and check them! 🚀 Try changing the number of tries in the loop below!
for tries in range(4):
guess = int(input('Guess: '))
print('Got your guess:', guess)Quick Check! 🧠
Test your guessing-game skills! ❓
Guess Asking Champion! 🎉
Great work! 🎉 You can ask for guesses!
input()asks the player 🗣️int()makes the guess a number 🔢==compares guess to secret ⚖️- A loop gives several tries 🔁
Next: giving hints like higher or lower! 📈📉
guess = int(input('Your guess: '))
print('You guessed', guess, '! 🎯')Frequently asked questions
Is the “Asking for Guesses” lesson free?
Yes — the full text of “Asking for Guesses” is free to read here on the web, and the Coding for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Coding for Kids course, upgrade to CoddyKit PRO.
What will I learn in “Asking for Guesses”?
Read the players guess. You practise Coding for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Coding for Kids?
No prior experience is required. Coding for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Asking for Guesses” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Coding for Kids lesson?
Yes. Every Coding for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Making a Secret Number
- Asking for Guesses
- Higher or Lower
- You Win!