Created
February 1, 2016 08:20
-
-
Save fer408/a7580dc286ff08cdd7d3 to your computer and use it in GitHub Desktop.
Intro to Programming Project 2 Variation
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
#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. | |
string1 = " Today i saw a NOUN on my VERB to the park earlier. So as i went to the bathroom to VERB a NOUN came out of nowhere" | |
string2 = "I like to VERB while playing with my favorite NOUN. my NOUN likes to VERB" | |
string3 = "Mike's favorite NOUN likes to VERB all over his bed.Mike likes to VERB in the Bathroom" | |
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 | |
# for the reverse mad libs generator i used allot of the code from the lesson with some tweaks to it of course | |
from random import randint | |
#this replaces the VERB with either the word walk or jog. | |
def random_verb(): | |
random_num = randint(0, 1) | |
if random_num == 0: | |
return "walk" | |
else: | |
return "jog" | |
#this function replaces the NOUN with either the word bird or dog | |
def random_noun(): | |
random_num = randint(0,1) | |
if random_num == 0: | |
return "bird" | |
else: | |
return "dog" | |
#this function puts it all together so that the reverse mad libs generator can work | |
def word_transformer(word): | |
if word == "NOUN": | |
return random_noun() | |
elif word == "VERB": | |
return random_verb() | |
else: | |
return word[0] | |
#this is the madlib function which runs the game | |
def process_madlib(madlib): | |
processed = "" | |
index = 0 | |
box_length = 4 | |
while index < len(madlib): | |
frame = madlib[index: index + box_length] | |
to_add = word_transformer(frame) | |
processed += to_add | |
if len(to_add) == 1: | |
index += 1 | |
else: | |
index += 4 | |
return processed | |
#calling this unites the madlib game with the difficulty selector | |
print process_madlib(difficulty_selector()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment