Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Quizzes
- easy_quiz = "'Portugal is a country in ___1___. Portugal is bordered to the \
- east by ___2___, and to the west by the ___3___ Ocean. ___4___ is the primary language \
- spoken in Portugal.'"
- medium_quiz = "'Tanzania is a country in ___1___. Tanzania is popular for \
- travelers interested in climbing Mount ___2___ or going on safari in the \
- ___3___ National Park. The island of ___4___ lies just to the east of Tanzania \
- and is popular for its beaches and marine life.'"
- hard_quiz = "'Thailand is a country in Southeast ___1___. A popular city in \
- northern Thailand is ___2___. Thailand has many ___3___ off its southern coast, \
- and is bordered to the south by ___4___, another beautiful country.'"
- # Answers
- easy_answers = ["europe", "spain", "atlantic", "portuguese"]
- medium_answers = ["africa", "kilimanjaro", "serengeti", "zanzibar"]
- hard_answers = ["asia", "chiang mai", "islands", "malaysia"]
- # A list of the blanks to be replaced by the player's guesses
- blanks = ["___1___", "___2___", "___3___", "___4___"]
- # Introduction Text
- print "Welcome to the Fill-in-the-Blanks Quiz!"
- # Main contents of game. For each blank in the quiz, asks the player to enter an answer. Players
- # have three attempts to answer each question. If they answer incorrectly, they will be prompted
- # to try again. If they answer correctly, the blank will be filled in and they will be asked
- # the next question. Once all questions are correctly answered, the game will say "You won!" and end.
- def play_game(quiz, answers):
- index = 0
- attempts_left = 3
- quiz = quiz.split()
- while index <= 3 and attempts_left > 0:
- for word in quiz:
- if word in blanks:
- user_guess = raw_input("Fill in number " + str(index + 1) + ": ").lower()
- if user_guess != answers[index]:
- attempts_left = attempts_left - 1
- if attempts_left == 0:
- print "Sorry - you lose!"
- break
- print "That's not correct! You have " + str(attempts_left) + " tries left!"
- else:
- quiz = " ".join(quiz)
- quiz = quiz.replace(blanks[index], user_guess)
- print "Correct!" + "\n" + quiz
- quiz = quiz.split()
- index = index + 1
- attempts_left = 3
- if index == 4:
- print "You won!"
- # Asks player to select level of difficulty. If they don't answer with either
- # easy, medium, or hard, it will ask them again.
- def select_difficulty():
- chosen_level = raw_input("Please select your level of difficulty: easy, medium, or hard: ").lower()
- if chosen_level == "easy":
- print "You've selected the easy quiz! You have 3 attempts to fill in each blank. Let's begin!"
- print easy_quiz
- return play_game(easy_quiz, easy_answers)
- elif chosen_level == "medium":
- print "You've selected the medium quiz! You have 3 attempts to fill in each blank. Let's begin!"
- print medium_quiz
- return play_game(medium_quiz, medium_answers)
- elif chosen_level == "hard":
- print "You've selected the hard quiz! You have 3 attempts to fill in each blank. Let's begin!"
- print hard_quiz
- return play_game(hard_quiz, hard_answers)
- else:
- print "I didn't understand your answer."
- select_difficulty()
- select_difficulty()
Add Comment
Please, Sign In to add comment