我如何从列表中随机 python select 一些东西,如果在输入提示中输入,它将显示预期的确切答案

How do I make python randomly select something from a list and if typed in the input prompt, it will show the exact answer as intended

基本上,我想做一个像我们之间的游戏,但又不同,只是为了好玩 无论如何,每当我尝试让它工作时,无论如何它都会说出我想要的信息。 这是代码:

import turtle   
t=turtle.Turtle()  
import random       

imposteris = ['red', 'blue', 'green', 'cyan', 'lime', 'black', 'white', 'purple', 'orange', 'brown']  
random.choice("imposteris")  
n = 1

print("Welcome to among them, you are a detective, figure out who the imposter is")   
meeting = int(input("Press 1 if you want to call a meeting"))   
if meeting:   
  input("A meeting has been called! Who do you think the imposter is?, Do either red, blue, green, cyan, lime, black, white, purple, orange, brown")   
  for i in range(n):   
    if random.choice(imposteris):   
      print("Congratulations, You caught the imposter.")      
    else:   
      print("He was a crewmate :/")

 

你必须 link 随机选择一个变量,所以在这种情况下:your_variable = random.choice(imposteris) 然后你可以用变量做任何你想做的事,例如:print(your_variable)

为了测试代码,我取出了你导入的 Turtle 模块,但你可以稍后再放回去。

import random

imposters = ['red', 'blue', 'green', 'cyan', 'lime', 'black', 'white', 'purple', 'orange', 'brown']

print("Welcome to among them, you are a detective, figure out who the imposter is\n")
print("Press 1 if you want to call a meeting")
meeting = int(input("> "))
if meeting:
    imposter = imposters[random.randint(0, len(imposters) - 1)]
    print(imposter)
    print("A meeting has been called! Who do you think the imposter is?, Do either red, blue, green, cyan, lime, black, white, purple, orange, brown")
    imposterGuess = str(input("> "))
if imposter == imposterGuess:
    print("Congratulations, You caught the imposter.")
else:
    print("%s was a crewmate :/" % imposterGuess)```