Skip to content

Instantly share code, notes, and snippets.

@johnzeringue
Forked from insipx/NameGenChallenge.py
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnzeringue/a269e3c73b41d542fd77 to your computer and use it in GitHub Desktop.
Save johnzeringue/a269e3c73b41d542fd77 to your computer and use it in GitHub Desktop.
import random
def sample(dictionary):
# the first argument can be omitted as it defaults to 0
randomIndex = random.randrange(len(dictionary))
return dictionary[randomIndex]
def promptForGender():
genderList = {0: "male", 1: "female"}
response = raw_input("What Name Gender would you like? (m/f) (enter 'r' for random)")
response = response.lower()
# convert user input into some sort of normalized gender format
# this could stay "m" and "f" instead
if response == "m":
return "male"
elif response == "f":
return "female"
elif response == "r":
return sample(genderList)
else:
print "please enter 'M' ,'F', or 'R' to initiate the Random Name Generator"
def genName():
boyNames = {0: "Jack",1: "Andrew", 2: "Mike",3: "Terry",4: "Torvald", 5: "Gatsby"}
girlNames = {0: "Alice", 1: "Hana", 2: "Clare", 3: "Janet", 4: "Daisy"}
gender = promptForGender()
if gender == "male":
return sample(boyNames)
elif gender == "female":
return sample(girlNames)
print "Welcome to the Simple Random Name Generator by Liquid Think!"
print genName()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment