Daily Python Projects
Python Code Dictations
Number Guessing Game - Python Code Dictation
0:00
-3:44

Number Guessing Game - Python Code Dictation

Level: Easy 🟡

What is this post about?

This is an audio code dictation to help learners memorize Python syntax. Follow these steps to complete a dictation:

  1. Open a code editor on your computer.

  2. Play the audio and type the narrated code while listening.

  3. Compare your code with the correct code below.

Correct Code

import random

# Generate a random number between 1 and 10
secret_number = random.randint(1, 10)

# Give the player 3 chances to guess the number
attempts = 3
while attempts > 0:
    guess = int(input("Guess the number (between 1 and 10): "))
    
    if guess == secret_number:
        print("Congratulations! You guessed it right.")
        break
    elif guess < secret_number:
        print("Too low! Try again.")
    else:
        print("Too high! Try again.")
    
    attempts -= 1

if attempts == 0:
    print(f"Sorry, the secret number was {secret_number}.")

Explore More Dictations

Discussion about this episode

User's avatar