Advertisement
SimeonTs

SUPyF2 P.-Mid-Exam/2 November 2019/2. - Experience Gaining

Nov 5th, 2019
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.42 KB | None | 0 0
  1. """
  2. Programming Fundamentals Mid Exam - 2 November 2019 Group 2
  3. Check your code: https://judge.softuni.bg/Contests/1862/Programming-Fundamentals-Mid-Exam-2-November-2019-Group-2
  4.  
  5. SUPyF2 P.-Mid-Exam/2 November 2019/2. - Experience Gaining
  6.  
  7. Problem:
  8. Write a program, that helps a player figure how many battles he will need to play in a battle video game,
  9. in order to unlock the next tank in the line.
  10. On the first line you will receive the amount of experience that is needed to unlock the tank.
  11. On the second line you will receive the count of battles. On the next lines,
  12. you will receive the experience the player can gain in every battle.
  13. Calculate if he can unlock the tank. Keep in mind that he gets 15% more experience for every third battle and
  14. 10% less for every fifth battle. You also need to stop the program as soon as he collects the needed experience.
  15. If he managed to gather the experience, print how many battles it took him in the following format:
  16. • "Player successfully collected his needed experience for {battleCount} battles."
  17. If he was not able to do it, print the following message:
  18. • "Player was not able to collect the needed experience, {neededExperience} more needed."
  19. Format the needed experience to the second decimal place.
  20. Input
  21. • On the first line you will receive the needed experience amount –  a real number in the range [0.0….400000.0]
  22. • On the second line you will receive the count of battles – an integer number in the range
  23. [0….500]
  24. • On the next lines you will receive the experience earned per battle – a real number in the range
  25. [0.0….5000.0]
  26. Output
  27. • If he managed to gather the experience:
  28. • "Player successfully collected his needed experience for {battleCount} battles."
  29. • If he was not able to do it:
  30. • "Player was not able to collect the needed experience, {neededExperience} more needed."
  31. NOTE: Format the needed experience to the second decimal place.
  32.  
  33. Examples:
  34.  
  35. Input:      Output:
  36. 500         Player successfully collected his needed experience for 5 battles.
  37. 5
  38. 50
  39. 100
  40. 200
  41. 100
  42. 30
  43.  
  44. Comments:
  45. The first line is the amount of the wanted experience.  – "500"
  46. The second line is the expected battles for which he has to collect the experience.  – "5"
  47. After that is the experience received for every battle:
  48. 50 + 100 + (200 + (200 * 15 %)) + 100 + (30 – (30 * 10 %)) = 507
  49. So on the console is printed :
  50. "Player successfully collected his needed experience for 5 battles."
  51.  
  52. Input:      Output:
  53. 500         Player was not able to collect the needed experience, 2.00 more needed.
  54. 5
  55. 50
  56. 100
  57. 200
  58. 100
  59. 20
  60.  
  61. Input:     Output:
  62. 400        Player successfully collected his needed experience for 4 battles.
  63. 5
  64. 50
  65. 100
  66. 200
  67. 100
  68. 20
  69. """
  70. needed_experience = float(input())
  71. battles_count = int(input())
  72. current_experience = 0
  73.  
  74. managed = False
  75.  
  76. for battle in range(1, battles_count + 1):
  77.     new_experience = float(input())
  78.     current_experience += new_experience
  79.     if battle % 3 == 0:
  80.         current_experience += new_experience * 0.15
  81.     if battle % 5 == 0:
  82.         current_experience -= new_experience * 0.1
  83.     if current_experience >= needed_experience:
  84.         print(f"Player successfully collected his needed experience for {battle} battles.")
  85.         managed = True
  86.         break
  87.  
  88. if not managed:
  89.     print(f"Player was not able to collect the needed experience, "
  90.           f"{(needed_experience - current_experience):.2f} more needed.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement