Generate a random number between 1 and 10. Ask the user to guess the number and print a

message based on whether they get it right or not.

Here is some Python code that generates a random number between 1 and 10 and prompts the user to guess it:

import random

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

# Ask the user to guess the number
guess = int(input("Guess a number between 1 and 10: "))

# Print a message based on whether the guess was correct
if guess == random_number:
print("You guessed correctly!")
else:
print("Sorry, that's not the right number. The correct number was", random_number)


You could name this code "random_number_guesser" or something similar.

Guess a number between 1 and 10: 5
Sorry, that's not the right number. The correct number was 8


This is what the user would see if they guessed 5 and the random number generated was 8. If the user guessed correctly, they would see the message "You guessed correctly!" instead.

Note that the output will vary depending on the random number generated and the user's guess.