Breaking down long function - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Breaking down long function (/thread-2633.html) |
Breaking down long function - LucasLambert - Mar-30-2017 Hey there. I need some help and guidance in breaking down a long function but can seem to grasp exactly how....: Any help would be greatly appreciated!! :) Onelove! def play_game(): level = get_level() quiz = game_data[level]['quiz'] print quiz answers_list = game_data[level]['answers'] blanks_index = 0 game_over = 0 answers_index = 0 guesses = 3 while blanks_index < 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 "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): time.sleep (3) else: guesses -= 1 if guesses == game_over: print "Wawaooohh, you lost..... :(" time.sleep (3) break else: print "please try again. one guess down." RE: Breaking down long function - Larz60+ - Mar-30-2017 This is a bit convoluted. Could you please show blanks RE: Breaking down long function - LucasLambert - Mar-30-2017 Hey sorry, It's quite a long piece of code. Essentially I have helper functions: get_level: User inputs raw_input check_answer: confirms from my dictionary list, answers and returns.. If correct or not... blanks = ["__1__","__2__","__3__", "__4__"] |