Advertisement
SimeonTs

SUPyF2 P.-Mid-Exam/6 August 2019. - Black Flag

Oct 28th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.61 KB | None | 0 0
  1. """
  2. Programming Fundamentals Mid Exam Retake - 6 August 2019
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1773#0
  4.  
  5. SUPyF2 P.-Mid-Exam/6 August 2019. - Black Flag
  6.  
  7. Problem:
  8. Pirates are invading the sea and you're tasked to help them plunder
  9. Create a program that checks if a target plunder is reached.
  10. First you will receive how many days the pirating lasts.
  11. Then you will receive how much the pirates plunder for a day.
  12. Last you will receive the expected plunder at the end.
  13. Calculate how much plunder the pirates manage to gather. Each day they gather plunder.
  14. Keep in mind that every third day they attack more ships and they add
  15. additional plunder to their total gain which is 50% of the daily plunder.
  16. Every fifth day the pirates encounter a warship and after the battle they lose 30% of their total plunder.
  17. If the gained plunder is more or equal to the target print the following:
  18. "Ahoy! {totalPlunder} plunder gained."
  19. If the gained plunder is less than the target. Calculate the percentage left and print the following:
  20. "Collected only {percentage}% of the plunder."
  21. Both numbers should be formatted to the 2nd decimal place.
  22. Input:
  23. • On the 1st line you will receive the days of the plunder – an integer number in the range [0…100000]
  24. • On the 2nd line you will receive the daily plunder – an integer number in the range [0…50]
  25. • On the 3rd line you will receive the expected plunder – a real number in the range [0.0…10000.0]
  26. Output:
  27. •  In the end print whether the plunder was successful or not following the format described above.
  28. Examples:
  29. Input:      Output:
  30. 5           Ahoy! 154.00 plunder gained.
  31. 40
  32. 100
  33. Comments:
  34. The days are 5 and the daily plunder is 40.
  35. On the third day the total plunder is 120 and since it is a third day,
  36. they gain an additional 50% from the daily plunder which adds up to 140.
  37. On the fifth day the plunder is 220,
  38. but they battle with a warship and lose 30% of the collected cargo and the total becomes 154.
  39. That is more than the expected.
  40.  
  41. Input:      Output:
  42. 10          Collected only 36.29% of the plunder.
  43. 20
  44. 380
  45. """
  46. days = int(input())
  47. plunder_for_a_day = int(input())
  48. expected_plunder = int(input())
  49.  
  50. total_plunder = 0
  51.  
  52. for day in range(1, days + 1):
  53.     total_plunder += plunder_for_a_day
  54.     if day % 3 == 0:
  55.         total_plunder += plunder_for_a_day / 2
  56.     if day % 5 == 0:
  57.         total_plunder *= 0.7
  58.  
  59. if total_plunder >= expected_plunder:
  60.     print(f"Ahoy! {total_plunder:.2f} plunder gained.")
  61. else:
  62.     print(f"Collected only {(100 * float(total_plunder) / float(expected_plunder)):.2f}% of the plunder.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement