yiddish.ninja
Menu
  • About
  • Bedtime Stories
Menu

Python Poetry

Posted on February 20, 2016February 26, 2016 by Greg

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.

Random Python Poetry
Python
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('.')

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • What is Programming?
  • Becoming a Raspberry Pi Certified Educator
  • MOD Pizza’s Cauliflower Crust
  • Keeping my resolutions
  • Pain and Python

Archives

Categories

Disclaimer

The views and opinions expressed on this site are my own and do not represent any organizations, projects. or businesses with which I am involved as an employee, member, participant, or leader.

Recent Comments

  • Ron on Lowe’s: A Case Study in Bad Customer Service
  • Greg on Viewing Someone’s Previous LinkedIn Posts
  • Abhiram Venkitela on Viewing Someone’s Previous LinkedIn Posts
  • Pikachu1902 on Sharing Your Local Minecraft Server Over the Internet
  • John MARTIN on Mags for your Canik TP40

No Warranty

I'm human, I'm imperfect, and I make mistakes. There is no guarantee of accuracy, serviceability, functionality, or applicability of anything I write or link to here. By viewing this site, you agree that you are solely responsible for all outcomes related to that act and release me from any liability.
©2019 yiddish.ninja | WordPress Theme by Superb Themes