Skip to content

Instantly share code, notes, and snippets.

@fer408
Created February 1, 2016 08:18
Show Gist options
  • Save fer408/8e426d4ab56d4294392c to your computer and use it in GitHub Desktop.
Save fer408/8e426d4ab56d4294392c to your computer and use it in GitHub Desktop.
Intro to programming Project 2 Tweak
#this is to ask the user which difficulty he/she would like to use.
print "what difficulty would you like to choose?"
print "press 1 for easy, 2 for medium or 3 for hard"
#these are the possible strings associated with each difficuty level.
parts_of_speech = ["PLACE","JOB","HOBBY","VERB","NOUN","ACTIVITY"]
string1 = " Today i saw a NOUN on my VERB to my JOB earlier.On another note i plan to ACTIVITY later on tonight"
string2 = "I like to VERB while playing with my favorite NOUN. my NOUN likes to VERB around my favorite PLACE "
string3 = "Mike's favorite NOUN likes to VERB all over his bed.Mike likes to HOBBY at his favorite PLACE"
easy = 1
medium = 2
hard = 3
#this is the function that selects the levels.
def difficulty_selector():
user_input = raw_input()
if user_input == '1':
print "easy it is"
return string1
if user_input == '2':
print "medium it is"
return string2
else:
print "hard it is"
return string3
#cool
# Checks if a word in parts_of_speech is a substring of the word passed in.
def word_in_pos(word, parts_of_speech):
for pos in parts_of_speech:
if pos in word:
return pos
return None
# Plays a full game of mad_libs. A player is prompted to replace words in ml_string,
# which appear in parts_of_speech with their own words.
def play_game(ml_string, parts_of_speech):
replaced = []
ml_string = ml_string.split()
for word in ml_string:
replacement = word_in_pos(word, parts_of_speech)
if replacement != None:
user_input = raw_input("Type in a: " + replacement + " ")
word = word.replace(replacement, user_input)
replaced.append(word)
else:
replaced.append(word)
replaced = " ".join(replaced)
return replaced
print play_game(difficulty_selector(), parts_of_speech)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment