简体   繁体   中英

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.

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

You can do:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM