Python - Randomly select words to display in a quiz [duplicate]

2024/10/4 16:10:46

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.

Answer

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

import randomwords = zip(wordlist1, wordlist2)
print random.choice(words)for word1, word2 in words:print word1, "is the opposite of", word2
https://en.xdnf.cn/q/120565.html

Related Q&A

How to extract only the english words from the list?

I tried to extract only the English words from the following list: l = [0, b, x14, x00, x1fP, xe0O, xd0, xea, i, x10, xa2, xd8, x08, x00, 00, x9d, x14, x00, x80, xcc, xbf, xb4, xdbLB, xb0, x7f, xe9, x9…

Javascript variable with html code regex email matching

This python script is not working to output the email address [email protected] for this case.This was my previous post.How can I use BeautifulSoup or Slimit on a site to output the email address from …

how to send a large array over tcp socket in python? is it possible to send? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 9 years ago.Improve…

Expand Python regex to list of all possible strings [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 5…

How can I group and sum a pandas dataframe? [duplicate]

This question already has answers here:How do I Pandas group-by to get sum?(11 answers)Closed 1 year ago.Ive had a good hunt for some time and cant find a solution so asking here. I have data like so:…

python add value to a list when iterate the list

values = [2,3,4] for v in values:values.append([v,255,255])Why do the statements above never end? I make a mistake in my code. However, I find it will never stop when I execute the code above.

resizing images from 64x64 to 224x224 for the VGG model

Can we resize an image from 64x64 to 256x256 without affecting the resolution is that a way to add zero on new row and column in the new resized output I m working on vgg and I get an error while addin…

Python slicing explained [duplicate]

This question already has answers here:How slicing in Python works(38 answers)Closed 6 years ago.OK I understand the basics, but can someone explain code copied from Gregs answer here:a[1::-1] # the …

Comparison between string characters within a list [duplicate]

This question already has an answer here:How to compare characters of strings that are elements of a list? [duplicate](1 answer)Closed 2 years ago.Having a Python list, containing same length strings,…