Advertisement
SimeonTs

SUPyF Exam Preparation 1 - 01. Sino the Walker

Aug 16th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.36 KB | None | 0 0
  1. """
  2. Basics OOP Principles
  3. Check your solution: https://judge.softuni.bg/Contests/Practice/Index/967#0
  4.  
  5. SUPyF Exam Preparation 1 - 01. Sino the Walker
  6.  
  7. Problem:
  8. Sino is one of those people that lives in SoftUni. He leaves every now and then,
  9. but when he leaves he always takes a different route, so he needs to know how much time it will take for him to go home.
  10. Your job is to help him with the calculations.
  11. You will receive the time that Sino leaves SoftUni, the steps taken and time for each step, in seconds.
  12. You need to print the exact time that he will arrive at home in the format specified.
  13. Input / Constraints
  14. • The first line will be the time Sino leaves SoftUni in the following format: HH:mm:ss
  15. • The second line will contain the number of steps that he needs to walk to his home.
  16.    This number will be an integer in range [0…2,147,483,647]
  17. • On the final line you will receive the time in seconds for each step.
  18.    This number will be an integer in range [0…2,147,483,647]
  19. Output
  20. • Print the time of arrival at home in the following format:
  21. o   Time Arrival: {hours}:{minutes}:{seconds}
  22. • If hours, minutes or seconds are a single digit number, add a zero in front.
  23. • If, for example, hours are equal to zero, print a 00 in their place. The same is true for minutes or seconds.
  24. • Time of day starts at 00:00:00 and ends at 23:59:59
  25.  
  26. Examples:
  27.  
  28. Input:
  29. 12:30:30
  30. 90
  31. 1
  32.  
  33. Output:
  34. Time Arrival: 12:32:00
  35.  
  36. Input:
  37. 23:49:13
  38. 5424
  39. 2
  40.  
  41. Output:
  42. Time Arrival: 02:50:01
  43. """
  44.  
  45. from datetime import datetime, timedelta
  46.  
  47. start_time = datetime.strptime(input(), "%H:%M:%S")
  48. added_time = timedelta(seconds=(float(input()) * float(input())))
  49. end_time = ((start_time + added_time).time())
  50. print(f"Time Arrival: {end_time}")
  51.  
  52.  
  53. # Another Option from different person, as mine will generate a problem with larger int's then the sys.max size:
  54. """
  55. def convert(seconds):
  56.    seconds = seconds % (24 * 3600)
  57.    hour = seconds // 3600
  58.    seconds %= 3600
  59.    minutes = seconds // 60
  60.    seconds %= 60
  61.  
  62.    return "%02d:%02d:%02d" % (hour, minutes, seconds)
  63.  
  64.  
  65. if __name__ == '__main__':
  66.  
  67.    time = input()
  68.    steps = int(input())
  69.    seconds_step = int(input())
  70.  
  71.    h, m, s = time.split(':')
  72.    sec = (int(h)*3600) + (int(m)*60) + int(s)
  73.    sec_home = sec + (steps*seconds_step)
  74.    print(f'Time Arrival: {convert(sec_home)}')
  75. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement