What is this post about?
This is an audio code dictation to help learners memorize Python syntax. Follow these steps to complete a dictation:
Open a code editor on your computer.
Play the audio and type the narrated code while listening.
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}.")
Share this post