import random x = int(raw_input("Number(1-6): ")) # note I made x an int while True: y = random.randint(1, 6) if x != y: break
Here is what the above code is Doing:
1. It’s asking the user for a number between 1 and 6.
2. It’s generating a random number between 1 and 6.
3. It’s comparing the two numbers. If they’re the same, it goes back to step 2.
4. If they’re not the same, it breaks out of the loop.