Why this simple python code always prints “incorrect” ?
import random
random_number = random.randint(1, 6)
guess = 0
while True:
guess = raw_input("Enter random number between 1-6: ")
if guess == random_number:
print(“correct”)
else:
print(“incorrect”)
Read up on raw_input(). It returns a string.
The code:
import random
random_number = random.randint(1, 6)
while True:
guess = int(raw_input("Enter random number between 1-6: "))
if guess == random_number:
print(“correct”)
else:
print(“incorrect”)
The output:
Found solution, thanks for help
import random
while True:
random_number = random.randint(1, 6)
guess = int(raw_input("Enter random number between 1-6: "))
if guess == random_number:
print(“correct”)
else:
print(“incorrect”)