Here’s an example Python code to generate a random number:
# Import the random module import random # Generate a random number between 1 and 10 random_number = random.randint(1, 10) # Print the random number print("The random number is:", random_number)
In this code, we first import the
random module, which provides several functions for generating random numbers.
We then use the
randint() function to generate a random integer between 1 and 10 (inclusive) and assign it to the variable
Finally, we use the
print() function to output the random number.
When you run this code, it should output a random number between 1 and 10. For example:
The random number is: 7
Note that each time you run this code, it will generate a different random number between 1 and 10. If you want to generate a random number within a different range, you can simply modify the arguments to the