Aaron Chapman
Aaron Chapman

Reputation: 44

Python - random.randint () issue

After randomly generating a number, I check to see if the user's input matches. If it does, print one line, if not, print another. Even if the user guesses correctly, the other line prints.

chosenNumber = input ("Choose a number: ")
int (chosenNumber)
diceRoll = random.randint (1,3)
print ("The number rolled is: ",diceRoll)
if diceRoll == chosenNumber:
      print ("WINNER")
else:
      print ("LOSER")

Thank you for any help.

Upvotes: 0

Views: 5550

Answers (1)

TerryA
TerryA

Reputation: 59974

int() does not turn the string to an integer in place because strings are immutable.

You can do:

chosenNumber = int(input ("Choose a number: "))

Upvotes: 3

Related Questions