简体   繁体   English

如何从列表中随机生成 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

Basically, I want to make a game something like among us, but different, just for fun Anyways whenever I try to make it work, it will say my desired message no matter what.基本上,我想制作一款类似于我们中间的游戏,但又有所不同,只是为了好玩。无论如何,无论何时我试图让它发挥作用,无论如何它都会说出我想要的信息。 Here's the code:这是代码:

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 :/")

 

You do have to link a variable to your random choice, so in this case: your_variable = random.choice(imposteris) then you can do whatever you want with the variable for example: print(your_variable)您确实必须将变量链接到您的随机选择,因此在这种情况下: your_variable = random.choice(imposteris)然后您可以对变量执行任何操作,例如: print(your_variable)

I took out your import of the Turtle module in order to test the code but you can put it back later.我取出了您导入的 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)```


暂无
暂无

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

相关问题 我如何从输入中随机选择一个单词(python) - how do i randomly select a word from an input (python) 如何从列表中随机选择一个变量,然后在python中修改它? - How do I randomly select a variable from a list, and then modify it in python? Python 3:如何使用用户输入并从词典列表中检索答案来制作游戏,然后使用积分系统? - Python 3: How do I make a game using user input and retrieving answer from a list of dictionaries, then use a point system? 我可以从列表中随机选择……但是如何将其用作不同命令的变量? 蟒蛇 - I can select randomly from a list… but how do I use this as a variable for different commands? Python 如何让我的 Discord Bot 对列表中的不同单词回复相同的答案? Python - How do I make my Discord Bot reply a same answer to different words from a list? Python 如果回答:BLAH导入脚本,如何创建一个像answer = raw_input()的python脚本 - How do I make a python script like answer = raw_input() if answer: BLAH import script 如何从列表中随机选择一个项目 - How do I randomly select an item from a list 如何从 python 中的输入随机 select - How to randomly select from an input in python Python:如何从字典键中随机选择一个值? - Python: How do I randomly select a value from a dictionary key? 如果我的答案包含某些内容,我该如何做出if陈述 - How do i make an if statement if my answer includes something
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM