SimeonTs

SUPyF2 P.-Mid-Exam/4 November 2018 - 02. Dungeonest Dark

Oct 31st, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.21 KB | None | 0 0
  1. """
  2. Technology Fundamentals Mid Exam - 4 November 2018
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1316#1
  4.  
  5. SUPyF2 P.-Mid-Exam/4 November 2018 - 02. Dungeonest Dark
  6.  
  7. Problem:
  8. As a young adventurer, you seek gold and glory in the darkest dungeons there are.
  9. You have initial health 100 and initial coins 0. You will be given a string, representing the dungeons rooms.
  10. Each room is separated with '|' (vertical bar): "room1|room2|room3…"
  11. Each room contains item or a monster and a number, separated by space. ("item/monster number")
  12. • If the first part is "potion": you are healed with the number in the second part.
  13. But your health cannot exceed your initial health (100). Print: "You healed for {0} hp.".
  14. After that, print your current health: "Current health: {0} hp.".
  15. • If the first part is "chest": You've found some coins, the number in the second part.
  16. Print: "You found {0} coins.".
  17. • In any other case you are facing a monster, you are going to fight.
  18. The second part of the room, contains the attack of the monster.
  19. You should remove the monster's attack from your health.
  20. o   If you are not dead (health <= 0) you've slain the monster, and you should print ("You slayed {monster}.")
  21. o   If you've died, print "You died! Killed by {monster}." and your quest is over.
  22. Print the best room you`ve manage to reach: "Best room: {room}".
  23. If you managed to go trough all the rooms in the dungeon, print on the next three lines:
  24. "You've made it!", "Coins: {coins}", "Health: {health}".
  25. Input / Constraints
  26. You receive a string, representing the dungeons rooms, separated with '|' (vertical bar): "room1|room2|room3…".
  27. Output
  28. Print the corresponding messages, described above.
  29.  
  30. Examples:
  31.  
  32. Input:
  33. rat 10|bat 20|potion 10|rat 10|chest 100|boss 70|chest 1000
  34.  
  35. Output:
  36. You slayed rat.
  37. You slayed bat.
  38. You healed for 10 hp.
  39. Current health: 80 hp.
  40. You slayed rat.
  41. You found 100 coins.
  42. You died! Killed by boss.
  43. Best room: 6
  44.  
  45. Input:
  46. cat 10|potion 30|orc 10|chest 10|snake 25|chest 110
  47.  
  48. Output:
  49. You slayed cat.
  50. You healed for 10 hp.
  51. Current health: 100 hp.
  52. You slayed orc.
  53. You found 10 coins.
  54. You slayed snake.
  55. You found 110 coins.
  56. You've made it!
  57. Coins: 120
  58. Health: 65
  59. """
  60. health = 100
  61. coins = 0
  62.  
  63. rooms = input().split("|")
  64. dead = False
  65.  
  66. for room in rooms:
  67.     potion_monster_chest = room.split()[0]
  68.     value = int(room.split()[1])
  69.  
  70.     if potion_monster_chest == "potion":
  71.         difference = 0
  72.         if health + value <= 100:
  73.             health += value
  74.             difference = value
  75.         else:
  76.             difference = value - ((health + value) - 100)
  77.             health = 100
  78.         print(f"You healed for {difference} hp.")
  79.         print(f"Current health: {health} hp.")
  80.  
  81.     elif potion_monster_chest == "chest":
  82.         coins += value
  83.         print(f"You found {value} coins.")
  84.  
  85.     else:
  86.         health -= value
  87.         if health > 0:
  88.             print(f"You slayed {potion_monster_chest}.")
  89.         else:
  90.             print(f"You died! Killed by {potion_monster_chest}.")
  91.             print(f"Best room: {rooms.index(room) + 1}")
  92.             dead = True
  93.             break
  94.  
  95. if not dead:
  96.     print(f"You've made it!\nCoins: {coins}\nHealth: {health}")
Add Comment
Please, Sign In to add comment