简体   繁体   English

Python-random.randint()问题

[英]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. int()不会将字符串转换为整数,因为字符串是不可变的。

You can do: 你可以做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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