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 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"}
genderList = {0: "M", 1: "F"}
askGender = raw_input("What Name Gender would you like? (m/f) (enter 'r' for random)")
askGender = askGender.lower()
if askGender != "m":
if askGender != "r":
if askGender !="f":
print "please enter 'M' ,'F', or 'R' to initiate the Random Name Generator"
if askGender == "r":
if sample(genderList) == "m":
return sample(boyNames)
else:
return sample(girlNames)
if askGender == "m":
return sample(boyNames)
elif askGender == "f":
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