Python - Randomly Select Words To Display In A Quiz
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', 'b
Solution 1:
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)
printrandom.choice(words)
for word1, word2 in words:
print word1, "is the opposite of", word2
Solution 2:
You can use the random
package and use the random.choice
function:
import random
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"]
word1 = random.choice(wordlists1)
word2 = random.choice(wordlists2)
print("Are "+word1+" and "+word2+" opposites?")
Post a Comment for "Python - Randomly Select Words To Display In A Quiz"