Guest User

Untitled

a guest
Mar 21st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. # Quizzes
  2. easy_quiz = "'Portugal is a country in ___1___. Portugal is bordered to the \
  3. east by ___2___, and to the west by the ___3___ Ocean. ___4___ is the primary language \
  4. spoken in Portugal.'"
  5. medium_quiz = "'Tanzania is a country in ___1___. Tanzania is popular for \
  6. travelers interested in climbing Mount ___2___ or going on safari in the \
  7. ___3___ National Park. The island of ___4___ lies just to the east of Tanzania \
  8. and is popular for its beaches and marine life.'"
  9. hard_quiz = "'Thailand is a country in Southeast ___1___. A popular city in \
  10. northern Thailand is ___2___. Thailand has many ___3___ off its southern coast, \
  11. and is bordered to the south by ___4___, another beautiful country.'"
  12.  
  13. # Answers
  14. easy_answers = ["europe", "spain", "atlantic", "portuguese"]
  15. medium_answers = ["africa", "kilimanjaro", "serengeti", "zanzibar"]
  16. hard_answers = ["asia", "chiang mai", "islands", "malaysia"]
  17.  
  18. # A list of the blanks to be replaced by the player's guesses
  19. blanks = ["___1___", "___2___", "___3___", "___4___"]
  20.  
  21. # Introduction Text
  22. print "Welcome to the Fill-in-the-Blanks Quiz!"
  23.  
  24. # Main contents of game. For each blank in the quiz, asks the player to enter an answer. Players
  25. # have three attempts to answer each question. If they answer incorrectly, they will be prompted
  26. # to try again. If they answer correctly, the blank will be filled in and they will be asked
  27. # the next question. Once all questions are correctly answered, the game will say "You won!" and end.
  28. def play_game(quiz, answers):
  29. index = 0
  30. attempts_left = 3
  31. quiz = quiz.split()
  32. while index <= 3 and attempts_left > 0:
  33. for word in quiz:
  34. if word in blanks:
  35. user_guess = raw_input("Fill in number " + str(index + 1) + ": ").lower()
  36. if user_guess != answers[index]:
  37. attempts_left = attempts_left - 1
  38. if attempts_left == 0:
  39. print "Sorry - you lose!"
  40. break
  41. print "That's not correct! You have " + str(attempts_left) + " tries left!"
  42. else:
  43. quiz = " ".join(quiz)
  44. quiz = quiz.replace(blanks[index], user_guess)
  45. print "Correct!" + "\n" + quiz
  46. quiz = quiz.split()
  47. index = index + 1
  48. attempts_left = 3
  49. if index == 4:
  50. print "You won!"
  51.  
  52. # Asks player to select level of difficulty. If they don't answer with either
  53. # easy, medium, or hard, it will ask them again.
  54. def select_difficulty():
  55. chosen_level = raw_input("Please select your level of difficulty: easy, medium, or hard: ").lower()
  56. if chosen_level == "easy":
  57. print "You've selected the easy quiz! You have 3 attempts to fill in each blank. Let's begin!"
  58. print easy_quiz
  59. return play_game(easy_quiz, easy_answers)
  60. elif chosen_level == "medium":
  61. print "You've selected the medium quiz! You have 3 attempts to fill in each blank. Let's begin!"
  62. print medium_quiz
  63. return play_game(medium_quiz, medium_answers)
  64. elif chosen_level == "hard":
  65. print "You've selected the hard quiz! You have 3 attempts to fill in each blank. Let's begin!"
  66. print hard_quiz
  67. return play_game(hard_quiz, hard_answers)
  68. else:
  69. print "I didn't understand your answer."
  70. select_difficulty()
  71. select_difficulty()
Add Comment
Please, Sign In to add comment