Advertisement
SimeonTs

SUPyF2 P.-Mid-Exam/30 June 2019/1 - Distance Calculator

Oct 28th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.31 KB | None | 0 0
  1. """
  2. Programming Fundamentals Mid Exam - 30 June 2019 Group 1
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1682#0
  4.  
  5. SUPyF2 P.-Mid-Exam/30 June 2019/1 - Distance Calculator
  6.  
  7. Problem:
  8. Create a program that calculates what percentage you’ve travelled.
  9. First, you will receive how many steps you’ve made.
  10. Then, you will receive how long 1 step is in centimeters.
  11. Last, you will receive the distance you need to travel in meters.
  12. Then you have to calculate what distance you have travelled with the steps given.
  13. Have in mind that every fifth step is 30% shorter than usual.
  14. You have to calculate what percentage of the distance you’ve travelled.
  15. In the end, print the percentage of the distance travelled, formatted to the 2nd decimal place, in the following format:
  16. "You travelled {percentage}% of the distance!"
  17. Input
  18. • On the 1st line you will receive the steps made – an integer number in the range [0…100000]
  19. • On the 2nd line you will receive the length of 1 step – a real number in the range [0.0…50.0]
  20. • On the 3rd line you will receive the distance you need to travel – an integer number in the range [0…100000]
  21. Output
  22. • In the end print the percentage of the distance travelled
  23.    formatted to the 2nd decimal place in the format described above.
  24. Constraints
  25. • The input will always be in the right format.
  26. • Percentage can be over 100%.
  27. Examples:
  28. Input:      Output:
  29. 100         You travelled 188.00% of the distance!
  30. 2
  31. 1
  32. Comments:
  33. The length of a step is 2 centimeters.
  34. Every fifth step will be 1.4 centimeters long.
  35. 20 shorter steps are made.
  36. The distance that has to be travelled is 1 meter.
  37. The distance travelled is 1.88 meters which is 188% of the distance that had to be travelled.
  38.  
  39. Input:      Output:
  40. 5000        You travelled 70.50% of the distance!
  41. 7.5
  42. 500
  43. """
  44. steps = int(input())
  45. step_in_cm = float(input())
  46. distance = float(input())
  47.  
  48.  
  49. def percentage(part, whole):
  50.     return f"{(100 * float(part)/float(whole)):.2f}"
  51.  
  52.  
  53. distance_traveled = 0
  54. for step in range(1, steps + 1):
  55.     if step % 5 == 0:
  56.         distance_traveled += step_in_cm * 0.7
  57.     else:
  58.         distance_traveled += step_in_cm
  59. distance_traveled_in_m = distance_traveled / 100
  60.  
  61. print(f"You travelled {percentage(distance_traveled_in_m, distance)}% of the distance!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement