Because chapter 9 of Invent Your Own Computer Games with Python is rather long, I thought we’d break in the middle and do a little messing with lists and string manipulation. Our word list is courtesy of randomlists.com.
Here’s a little example of the program. The kids can borrow what they see fit and come up with creative ways to change how it works.
For a challenge, make sure no word appears twice,
If you’ve stumbled on this randomly, pop it in your favorite Python 3 editor and have fun.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import string import random words = "abounding death picayune shut field children heat dime phobic scold bomb wanting brave slippery learned alike cute blind inquisitive chemical trouble moor blue-eyed tow whispering silky birds show selection astonishing nest harass interesting rotten trip grandmother bruise scare lucky broken lumpy iron trite cover brake care pickle branch helpful rule story badge march nice defective beginner spotty mitten bead torpid irritating crime instruct bore stove deadpan warlike spooky icky blade violent pink tangible stimulating orange precious alert tin mailbox float finger jail snore fresh brush tranquil jar explain desire basket activity fireman peck angle powder lamentable snake second-hand squeamish pumped exclusive overflow enter planes scissors license vanish messy shame sheep army crack vagabond island sticks judicious worried puzzling jazzy breath dog suspend sister plants spiky many horn ill comb obnoxious part trick nose grubby far beds spiders curly name grieving vulgar shave capricious tightfisted calculator top judge macho feeling dry mine red wrench scratch step thaw sleepy sip ambiguous dirty relation memory sweater mark ants versed awful nauseating rainy invention drop callous guarded sense uninterested knot sleet porter plot cover erratic punch moon longing influence unarmed hollow whip superb competition sassy obsolete notice riddle pat multiply icy control tidy".split() def getWord(): num = random.randint(0, len(words)-1) return words[num] for i in range(1, 40): word = getWord() if i == 1: print(word.capitalize(), end='') else: per = random.randint(0,6) if per == 4: print('.\n' + word.capitalize(), end='') else: print(' ' + word, end='') print('.') |