Fill in the blanks game So I've coded a fill in the blanks game but my last procedure, play_game() is far too long.
Trying to figure out how to divide it into two functions:


Initialize
process_answer




import time
from time import sleep

name = raw_input("Hey there, what's your name?") #Basic raw_input
intro = "Welcome to my Udacity, Mad-Libs game " + name #text plus value of "name"


blanks = ["__1__","__2__","__3__", "__4__"]


questions_easy = '''Python is an __1__ oriented __2__ programming language that has become very popular. It was created by __3__ Van Rossum.Python has been used widely, especially for __4__ learning.'''

questions_medium = '''Python has full support for object-__1__ programming including user-defined __2__, inheritance,
 and run-time binding of methods. Python has an extensive standard __3__, which is one of the main reasons for its popularity.
 Python was first created in __4__ 1989'''

questions_hard = '''Python is intended to be a highly readable __1__. It is designed to have an clear visual __2__.
Essencially the first step when creating a new program is creating a "draft" code also called __3__. This will allow you to have a basic idea on how the code
should be structured. When your code is complete and ready to testing for __4__ inputs and outputs.'''


answers_list_easy = ["object", "dynamic", "Guido", "machine"]
answers_list_medium = ["oriented", "classes", "library", "December"]
answers_list_hard = ["language", "layout", "pseudocode", "valid"]


game_data = {
   'easy': {
        'quiz': questions_easy,
        'answers': answers_list_easy,
        'message': "you chose easy, okay"
    },
   'medium': {
        'quiz': questions_medium,
        'answers': answers_list_medium,
        'message': "You chose medium, a fair challenge"
    },
   'hard': {
        'quiz': questions_hard,
        'answers': answers_list_hard,
        'message': "So you're a tough nugget aren't ya!!"
    }
}


def get_level(): #Inputs easy, medium or hard. Output, Relevant questions and answers.
    pick_level = raw_input("Type in your difficulty level. Choose from easy, medium or hard")
    while pick_level not in ["easy", "medium", "hard"]:
        pick_level = raw_input("Invalid input, please try again. Choose from easy, medium or hard")
    print game_data[pick_level]['message']
    return pick_level


def check_answer(user_answer, answers_list, answers_index):
    if user_answer == answers_list[answers_index]:
        return "right_answer"
    return "Wrong"
    pass

def you_lost():
    print "Wawaooohh, you lost..... :("
    time.sleep (3)
def you_win():
    print "We got ourselves a winner!!"
    time.sleep (3)



def play_game():
    level = get_level()
    quiz = game_data[level]['quiz']
    print quiz
    answers_list =  game_data[level]['answers']
    blanks_index = 0
    answers_index = 0
    guesses = 3

    while blanks_index &lt; len(blanks):
        user_answer = raw_input("So what's your answer to question " + blanks[blanks_index] + "? : ")
        if check_answer(user_answer,answers_list,answers_index) == "right_answer":
            print "\n nice job! that is the right answer!\n"
            quiz = quiz.replace(blanks[blanks_index], user_answer.upper())
            blanks_index += 1
            answers_index += 1
            guesses = 3
            print quiz
            if blanks_index == len(blanks):
                return you_win()

        else:
            guesses -= 1
            if guesses == 0:
                return you_lost()
                break
            print "Wrong!! Please try again. you have " + str (guesses) + " guesses left!"




play_game()
from time import sleep


Since you already imported time and are only calling time.sleep, this import is obsolete.



name = raw_input("Hey there, what's your name?") #Basic raw_input
intro = "Welcome to my Udacity, Mad-Libs game " + name #text plus value of "name"


The comments at the end of the lines do not tell you anything that is not already in the code, so you don't need them. Comments should usually tell you, why something is done, not what is done. What is done is already in the code.



answers_list_easy = ["object", "dynamic", "Guido", "machine"]


Having the type in the variable name is not needed, and rather bad practice. You might want to change the type later, for example to a tuple. Using a plural name (like answers_easy or easy_answers) already tells you (and possibly other developers) that the variable contains a collection, probably a sequence of answers (and a list is a kind of sequence).



game_data = {
   'easy': {
        'quiz': questions_easy,
        'answers': answers_list_easy,
        'message': "you chose easy, okay"
    },
   'medium': {
        'quiz': questions_medium,
        'answers': answers_list_medium,
        'message': "You chose medium, a fair challenge"
    },
   'hard': {
        'quiz': questions_hard,
        'answers': answers_list_hard,
        'message': "So you're a tough nugget aren't ya!!"
    }
}


This is not pretty, and probably useless. Since you need to access these values via strings as keys anyway, you might as well just access the global variables. These nested dictionaries do not really simplify the access to the variables, rather make it harder, and since at no point in the future "easy" will suddenly point towards questions_medium, you do not need to abstract the variable access.



def get_level(): #Inputs easy, medium or hard. Output, Relevant questions and answers.
    pick_level = raw_input("Type in your difficulty level. Choose from easy, medium or hard")
    while pick_level not in ["easy", "medium", "hard"]:
        pick_level = raw_input("Invalid input, please try again. Choose from easy, medium or hard")
    print game_data[pick_level]['message']
    return pick_level


Printing the level here is a side effect that you might want to prevent. The method should do only what its name implies, which is getting the level. A better name might be ask_level or input_level, since get is normally used for just returning a value that is already there. Then you can print the return value where you call this method.



def check_answer(user_answer, answers_list, answers_index):
    if user_answer == answers_list[answers_index]:
        return "right_answer"
    return "Wrong"
    pass


This name is not good, because it does not tell you what kind of answer is being checked, and what a positive result means. A better name would be is_answer_correct, or just is_correct if the parameter names are explicit enough (which I would say here they are).

Considering that the method just does a simple logical comparison with values that are all provided as parameters, you might just remove the method and replace its calls with the comparison.

As already hinted by kyrill in a comment, the method should not return strings (which are even very inconsistent here), but Trueor False boolean values. Then you can handle printing out the strings where you call the method depending on its result. And the pass does not do anything, actually it never does anything, but everything that comes after a return will not be reached.



you_lost and you_win are bad method names, and the methods alltogether are obsolete, since it is more readible to just see these 2 lines in your code than not knowing what you_lost() actually does.



blanks_index = 0
# [...]
while blanks_index &lt; len(blanks):
    # your code


Here you should iterate using a for-loop:

for blank in blanks:
    # your code