[英]How to make a non list Loop that will select 4 random numbers from 1-10, and display them, but they cannot be the same?
import random
counter = 0
count = 0
counting = 0
valueOne = 0
valueTwo = 0
while counter ==0:
playerOne = random.randint(1,10)
number = random.randint(1,10)
About right here is where I get confused. 关于这里,这让我感到困惑。 It will run the loop, but every time it runs, the random values get reset, and even if the first time it prints a random number, the second time it might print the same and so forth. 它将运行循环,但是每次运行时,随机值都会重置,即使第一次打印随机数,第二次也可能打印相同,依此类推。
if number == playerOne:
count = count + 1
if number != playerOne:
valueOne = playerOne
if number != valueOne:
print("lotto number",number)
counting = counting + 1
if counting >= 4:
print("it took you this many trys",count)
input('play again?')
counting = 0
count = 0
Should list the numbers in 1-10 (inclusive) then randomly sample them. 应列出1-10(含)之间的数字,然后随机抽样。
random.sample(range(1,11), 4)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.