【发布时间】:2016-07-15 14:46:13
【问题描述】:
我正在尝试制作“终端破解”游戏,但我被困在某个地方。
这是我的代码目前的样子:
import random
candidateWords = ['AETHER', 'BADGED', 'BALDER', 'BANDED', 'BANTER', 'BARBER'] #etc, etc
def wordlist():
for index, item in enumerate(random.sample(list(candidateWords), 8)):
print(index, ") ", item, sep='')
one = random.choice(candidateWords)
print(one)
print("Welcome to the Guess-The-Word Game.\nThe Password is one of these words:")
我正在尝试制作一个包含 8 个单词的列表并枚举它,以便为每个单词提供一个数字。然后,从这8个词中,我需要随机选择一个词作为答案,但我不知道怎么做。
我想使用random.sample() 和random.choice()。
【问题讨论】:
-
注意:我忘记从 wordlist() 中取出 (word)。请忽略:)和“one = random.choice(candidateWords) print(one)”部分完全是我对做我想做的事的猜测。它不起作用
标签: python python-3.x random shuffle