You can generate random numbers using the module
random. There's lots of ways to use the module, so you may want to check out the documentation for all the information. This is an example on how it could be done:
Code:
import random
# Generate a number between 1 and 10 (including 1 and 10)
number = random.randint(1, 10)
You should consider modifying your code a little too. You've hardcoded all the possibilities, which is inefficient. I would rather compare the input with the random number.
Code:
# Check if the input is valid (1-10)
if input >= 1 and input <= 10:
# Check if the input is greater than the random number
if input > number:
print "The random number is less than %d" % input
# Check if the input is less than the random number
elif input < number:
print "The random number is greater than %d" % input
# If non of the expressions above were true, it must be the right input.
else:
print "You guessed the right number, congratulations!"