I'm very new to python and programming!
I need to write a program that has 4 tuples with 5 elements each. One tuple should have verbs, one tuple should have nouns, one tuple should have adjectives, and one tuple should have adverbs. Then I have to use a randomly generated numbers between 0 and 4 to pick one of the elements from each tuple. This is what I have so far:
import random
nouns = ("puppy", "car", "rabbit", "girl", "monkey")
verbs = ("runs", "hits", "jumps", "drives", "barfs")
adv = ("crazily.", "dutifully.", "foolishly.", "merrily.", "occasionally.")
adj = ("adorable", "clueless", "dirty", "odd", "stupid")
num = random.randrange(0,5)
print (num)
Can someone show me what I'm doing wrong?
Generate a random letter using a string and a random module The string module has a special function ascii_letters which returns a string containing all the alphabets from a-z and A-Z, i.e. all the lowercase and uppercase alphabets.
You can use random.choice
within a list comprehension then concatenate the selected list with join
:
>>> l=[nouns,verbs,adj,adv]
>>> ' '.join([random.choice(i) for i in l])
'girl runs dirty crazily.'
>>> ' '.join([random.choice(i) for i in l])
'monkey hits clueless occasionally.'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With