1

Helloo

I'm trying to make a simple game where you have to choose either 1 or 2 and one of them is correct. I've used a simple random generator to choose either 1 or 2 as the correct answer.

def guess():

print("")
print("Select a number, 1 or 2")
print("")
from random import randint
ran = randint(1, 2)
nmr = input("")
if nmr == ran:
    print("That's correct!")
else:
    print("Wrong number")

Every time I answer it prints "Wrong number".

I've also tried printing the random number before answering but it still takes it as incorrect. Any idea what is wrong there?

1 Answers1

0

The problem is that you are comparing a string with an int. That always gives False.

ran = randint(1, 2)     #int
nmr = input("")         #str

So for it to work, either convert ran to str or nmr to int

Kaushik NP
  • 6,733
  • 9
  • 31
  • 60