Python-随机选择要在测验中显示的单词 [英] Python - Randomly select words to display in a quiz

查看:105
本文介绍了Python-随机选择要在测验中显示的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助.这里有我的两个列表:

I'm in need of some help. Here we have my two lists:

wordlists1 = ["hot","summer", "hard", "dry", "heavy", "light", "weak", "male",
             "sad", "win",  "small","ignore", "buy", "succeed", "reject", "prevent", "exclude"]

wordlists2 = ["cold", "winter", "soft", "wet", "light", "darkness", "strong", "female", "happy", "lose", "big",
         "pay attention", "sell", "fail", "accept", "allow", "include"]

好的,很多人误会我,所以我有这两个列表,我使用random.choice从每个列表中选择一个单词,一旦我们有了这些单词,我就需要将它们打印出来作为一个问题,例如例如,如果选择了高温和低温,那么它将显示为高温到低温,而低温到___?".我真的需要帮助,详细的步骤将不胜感激.

Okay, so many people are misunderstanding me, so I have these two lists, I use the random.choice to pick a word from each lists, once we have those words, I needed them to be printed out as a question such as, if hot and weak are selected, then it would be displayed as, "Hot is to cold as weak is to___?" I really need help on this, and detailed steps would be appreciated.

推荐答案

使用 random 库进行随机选择,并使用 zip 来确保每个元素都与之相反:

Use the random library to make a random choice and use zip to make sure each element is associated with it's opposite:

import random

words = zip(wordlist1, wordlist2)
print random.choice(words)

for word1, word2 in words:
    print word1, "is the opposite of", word2

这篇关于Python-随机选择要在测验中显示的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆