-
-
Save johnzeringue/a269e3c73b41d542fd77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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