-4

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"]

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.

iHazo
  • 29
  • 3

3 Answers3

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)
print random.choice(words)

for word1, word2 in words:
    print word1, "is the opposite of", word2
smac89
  • 39,374
  • 15
  • 132
  • 179
0

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?")
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
0

Try...

import random      
print(" question " + random.choice(wordlists1) + " question " + random.choice(wordlists2))
eternauta
  • 53
  • 5
  • Well the problem is that you have to keep the words in pairs too. Is not completely random. You wanna have cold and hot in the same question right? Otherwise you would have questions like "Hot is to allowed as male is to ___" which doesn't make sense to me. – eternauta Jan 08 '15 at 03:38
  • Try creating the lists in two dimensions. – eternauta Jan 08 '15 at 03:53