fork download
  1. INTRO_MESSAGE = ('You are in a locked room.\n'
  2. 'You will need to OPEN DOOR to ecape this terrible trap.\n'
  3. 'What will you do?\n')
  4.  
  5. DOOR_MESSAGE = 'You need to OPEN DOOR to escape this insufferable imprisonment.\n'
  6.  
  7. PICK_UP_KEY_MESSAGE = 'With a determined display of digit dexterity you picked up the KEY!\n'
  8.  
  9. HAS_KEY_MESSAGE = 'You are currently holding a KEY, your mind is filled with all the possible uses you could have ' \
  10. 'for such an item! But for now you ponder if it could fit in the DOOR?\n'
  11.  
  12. LOCKED_DOOR_MESSAGE = 'The DOOR is currently locked, perhaps you can find a KEY?\n'
  13.  
  14. OPEN_DOOR_MESSAGE = 'The DOOR swings open and you make a grand escape, vowing to NEVER be outsmarted ' \
  15. 'by a strong breeze and automatically locking door ever again!\n'
  16.  
  17. OTHER_OPTION_MESSAGE = 'Try to stay focused, you need to OPEN DOOR.\n'
  18.  
  19.  
  20. def play_the_game():
  21. print(INTRO_MESSAGE)
  22.  
  23. has_key = False
  24. is_door_unlocked = False
  25. while not is_door_unlocked:
  26. action = input()
  27. match action:
  28. case 'door':
  29. print(DOOR_MESSAGE)
  30. case 'key':
  31. has_key = pick_up_key(has_key)
  32. case 'open door':
  33. is_door_unlocked = try_open_door(has_key)
  34. case _:
  35. print(OTHER_OPTION_MESSAGE)
  36.  
  37.  
  38. def try_open_door(has_key):
  39. if has_key:
  40. print(OPEN_DOOR_MESSAGE)
  41. else:
  42. print(LOCKED_DOOR_MESSAGE)
  43. return has_key
  44.  
  45.  
  46. def pick_up_key(has_key):
  47. if has_key:
  48. print(HAS_KEY_MESSAGE)
  49. else:
  50. print(PICK_UP_KEY_MESSAGE)
  51. return True
  52.  
  53.  
  54. if __name__ == '__main__':
  55. while True:
  56. play_the_game()
  57. print('Do you want to play again?')
  58. if not input() == "yes":
  59. break
  60.  
Runtime error #stdin #stdout #stderr 0.05s 62860KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
  File "prog.py", line 27
    match action:
          ^
SyntaxError: invalid syntax