Silly Name Generator
Tags: literateprogramming, python, programmingpractice
Published: 2018-12-07 15:46:59

---
title: Silly Name Generator
published: true
description: Practice from impractical python.
tags: literate programming, python, programming practice
---


# Table of Contents

1.  [Introduction](#org8fe4880)
2.  [Name Lists](#org23be92e)
    1.  [First Names](#org1cf212e)
    2.  [Last Names](#orgdcd08b3)
3.  [Choosing a Name](#orgfbbe1ca)
4.  [Main](#org3d8d59a)



<a id="org8fe4880"></a>

# Introduction

This is the first of the [Impractical Python](https://nostarch.com/impracticalpythonprojects) book by Lee Vaughan.
I aim to do every project in this book, as a literate program in my own style.
As such please be kind, I am only a hobbyist that is aiming to learn.


<a id="org23be92e"></a>

# Name Lists


<a id="org1cf212e"></a>

## First Names

First things first, pun intended.
We need to have a list for the python program to choose from.
In python its easiest to do that with a list or tuple. The book used a tuple as it never
changes durring execution so there is no need for a list.
Admittedly I copy-pasted this section and the last names because I did not want to type them all.

    firstnames = ('Baby Oil', 'Bad News', 'Big Burps', "Bill 'Beenie-Weenie'",
    	 "Bob 'Stinkbug'", 'Bowel Noises', 'Boxelder', "Bud 'Lite' ",
    	 'Butterbean', 'Buttermilk', 'Buttocks', 'Chad', 'Chesterfield',
    	 'Chewy', 'Chigger', 'Cinnabuns', 'Cleet', 'Cornbread', 'Crab Meat',
    	 'Crapps', 'Dark Skies', 'Dennis Clawhammer', 'Dicman', 'Elphonso',
    	 'Fancypants', 'Figgs', 'Foncy', 'Gootsy', 'Greasy Jim', 'Huckleberry',
    	 'Huggy', 'Ignatious', 'Jimbo', "Joe 'Pottin Soil'", 'Johnny',
    	 'Lemongrass', 'Lil Debil', 'Longbranch', '"Lunch Money"', 'Mergatroid',
    	 '"Mr Peabody"', 'Oil-Can', 'Oinks', 'Old Scratch', 'Ovaltine',
    	 'Pennywhistle', 'Pitchfork Ben', 'Potato Bug', 'Pushmeet',
    	 'Rock Candy', 'Schlomo', 'Scratchensniff', 'Scut',
    	 "Sid 'The Squirts'", 'Skidmark', 'Slaps', 'Snakes', 'Snoobs',
    	 'Snorki', 'Soupcan Sam', 'Spitzitout', 'Squids', 'Stinky',
    	 'Storyboard', 'Sweet Tea', 'TeeTee', 'Wheezy Joe',
    	 "Winston 'Jazz Hands'", 'Worms')


<a id="orgdcd08b3"></a>

## Last Names

Same idea as firstnames. But for last names!

    
    lastnames = ('Appleyard', 'Bigmeat', 'Bloominshine', 'Boogerbottom',
    	'Breedslovetrout', 'Butterbaugh', 'Clovenhoof', 'Clutterbuck',
    	'Cocktoasten', 'Endicott', 'Fewhairs', 'Gooberdapple', 'Goodensmith',
    	'Goodpasture', 'Guster', 'Henderson', 'Hooperbag', 'Hoosenater',
    	'Hootkins', 'Jefferson', 'Jenkins', 'Jingley-Schmidt', 'Johnson',
    	'Kingfish', 'Listenbee', "M'Bembo", 'McFadden', 'Moonshine', 'Nettles',
    	'Noseworthy', 'Olivetti', 'Outerbridge', 'Overpeck', 'Overturf',
    	'Oxhandler', 'Pealike', 'Pennywhistle', 'Peterson', 'Pieplow',
    	'Pinkerton', 'Porkins', 'Putney', 'Quakenbush', 'Rainwater',
    	'Rosenthal', 'Rubbins', 'Sackrider', 'Snuggleshine', 'Splern',
    	'Stevens', 'Stroganoff', 'Sugar-Gold', 'Swackhamer', 'Tippins',
    	'Turnipseed', 'Vinaigrette', 'Walkingstick', 'Wallbanger', 'Weewax',
    	'Weiners', 'Whipkey', 'Wigglesworth', 'Wimplesnatch', 'Winterkorn',
    	'Woolysocks')


<a id="orgfbbe1ca"></a>

# Choosing a Name

To choose things, we need to use python's random module.
Random does lots of neat things in generating sudo random numbers.
Random.choice is what were gonna use for this one.

    import random

After the names are choosen, they are returned so that they can be displayed.

    def chooser(firstnames,lastnames):
        firstname = random.choice(firstnames)
        lastname = random.choice(lastnames)
        return (firstname, lastname)


<a id="org3d8d59a"></a>

# Main

Finally, we put it all together.
Technically, I should hafve written a "main" block, but this will work instead.
Chooser is outside incase you need it for something.

In essence, this program picks two names from a random list, returns them to the variables
firstname and lastname, then prints them.

Personally I think the original author used to many newlines, but whatever.

    # Check sillyname.org for details
     # Imports
    import sys
    import random
    
    # Internal Functions
    def chooser(firstnames,lastnames):
        firstname = random.choice(firstnames)
        lastname = random.choice(lastnames)
        return (firstname, lastname)
    
    
    
    
    # Main script
    
    
    
    
    def main():
        print("Welcome to the Pysch 'side kick name picker'!\n")
        print("A name just like Sean would pick for Gus:\n\n")
        firstnames = ('Baby Oil', 'Bad News', 'Big Burps', "Bill 'Beenie-Weenie'",
    	 "Bob 'Stinkbug'", 'Bowel Noises', 'Boxelder', "Bud 'Lite' ",
    	 'Butterbean', 'Buttermilk', 'Buttocks', 'Chad', 'Chesterfield',
    	 'Chewy', 'Chigger', 'Cinnabuns', 'Cleet', 'Cornbread', 'Crab Meat',
    	 'Crapps', 'Dark Skies', 'Dennis Clawhammer', 'Dicman', 'Elphonso',
    	 'Fancypants', 'Figgs', 'Foncy', 'Gootsy', 'Greasy Jim', 'Huckleberry',
    	 'Huggy', 'Ignatious', 'Jimbo', "Joe 'Pottin Soil'", 'Johnny',
    	 'Lemongrass', 'Lil Debil', 'Longbranch', '"Lunch Money"', 'Mergatroid',
    	 '"Mr Peabody"', 'Oil-Can', 'Oinks', 'Old Scratch', 'Ovaltine',
    	 'Pennywhistle', 'Pitchfork Ben', 'Potato Bug', 'Pushmeet',
    	 'Rock Candy', 'Schlomo', 'Scratchensniff', 'Scut',
    	 "Sid 'The Squirts'", 'Skidmark', 'Slaps', 'Snakes', 'Snoobs',
    	 'Snorki', 'Soupcan Sam', 'Spitzitout', 'Squids', 'Stinky',
    	 'Storyboard', 'Sweet Tea', 'TeeTee', 'Wheezy Joe',
    	 "Winston 'Jazz Hands'", 'Worms')
    
        lastnames = ('Appleyard', 'Bigmeat', 'Bloominshine', 'Boogerbottom',
    	'Breedslovetrout', 'Butterbaugh', 'Clovenhoof', 'Clutterbuck',
    	'Cocktoasten', 'Endicott', 'Fewhairs', 'Gooberdapple', 'Goodensmith',
    	'Goodpasture', 'Guster', 'Henderson', 'Hooperbag', 'Hoosenater',
    	'Hootkins', 'Jefferson', 'Jenkins', 'Jingley-Schmidt', 'Johnson',
    	'Kingfish', 'Listenbee', "M'Bembo", 'McFadden', 'Moonshine', 'Nettles',
    	'Noseworthy', 'Olivetti', 'Outerbridge', 'Overpeck', 'Overturf',
    	'Oxhandler', 'Pealike', 'Pennywhistle', 'Peterson', 'Pieplow',
    	'Pinkerton', 'Porkins', 'Putney', 'Quakenbush', 'Rainwater',
    	'Rosenthal', 'Rubbins', 'Sackrider', 'Snuggleshine', 'Splern',
    	'Stevens', 'Stroganoff', 'Sugar-Gold', 'Swackhamer', 'Tippins',
    	'Turnipseed', 'Vinaigrette', 'Walkingstick', 'Wallbanger', 'Weewax',
    	'Weiners', 'Whipkey', 'Wigglesworth', 'Wimplesnatch', 'Winterkorn',
    	'Woolysocks')
        while True:
    	firstname, lastname = chooser(firstnames, lastnames)
    	print("{} {}".format(firstname, lastname, file=sys.stderr))
    	print("\n\n")
    
    	try_again=input("\n\nTry again? (press n to quit)\n")
    	if try_again.lower() == 'n':
    	    break
    
        input("press Enter to exit")
    
    
    
    if __name__ == '__main__':
        main()
        sys.exit()

to use it, justt run sillyname.py from the commandline.
like so:

    ./sillyname.py

ant it will output something like this:

    ./sillyname.py
    Welcome to the Pysch 'side kick name picker'!
    
    A name just like Sean would pick for Gus:
    
    
    Chesterfield Sugar-Gold
    
    
    
    
    
    Try again? (press n to quit)

Overall, I hope you enjoyed this little read.