The input()
returns a string, so you have a string in user_input
. In dice1
, you have an integer. Try print(type(user_input))
and print(type(dice1))
. You cannot compare values of different types.
Convert the value in user_input
to an int
, then compare it with dice1
, like so:
import random
dice1 = random.randint(1, 2)
user_input = input("Guess a number: ")
user_input = int(user_input)
# You could replace the above two user_input statements with:
# user_input = int(input("Guess a number: ")) # Uncomment before using
if dice1 == user_input:
print("Well Done!")
else:
print("Try again")
Running the above code:
Guess a number: 1
Well Done!
>>>
More about input():
input([prompt])
If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that.