1
+ from datetime import timedelta ,datetime
2
+
3
+ time1 = input ("Time in (00:00:00) format limit(23:59:59)" )
4
+ speed = input ("Speed in this (1.50) format limit(9.99)" )
5
+
6
+ #for error checking of input if needed
7
+ '''
8
+ #time1 limit
9
+ if len(time1) == 8:
10
+ conditions = (time1[0] in '012',time1[1] in '0123456789', # conditions for true input
11
+ time1[2] == ':',time1[3] in '012345',
12
+ time1[4] in '0123456789',time1[5] == ':',
13
+ time1[6] in '012345',time1[7] in '0123456789')
14
+ if all(conditions):
15
+ print("OK")
16
+
17
+ #speed limit
18
+ if len(speed) == 4:
19
+ conditions = (len(speed) == 4, speed[1] == '.', speed[0] in '0123456789', # conditions for true
20
+ speed[2] in '0123456789', speed[3] in '0123456789')
21
+ if all(conditions):
22
+ print("ok")
23
+ '''
24
+
25
+ #main function/code
26
+ def Calculate_result_time_and_saved_time (time1 ,speed ):
27
+ original_total_seconds = (int (time1 [0 ]+ time1 [1 ]) * 3600 )+ (int (time1 [3 ]+ time1 [4 ]) * 60 ) + (int (time1 [6 ]+ time1 [7 ]))
28
+ calculated_result_seconds = float (original_total_seconds )/ float (speed ) # result
29
+ rounded_calculated_result_seconds = round (calculated_result_seconds , 0 ) # removing decimal part
30
+ result_time = timedelta (seconds = rounded_calculated_result_seconds ) # changing format
31
+ datetime1 = datetime .strptime (time1 ,"%H:%M:%S" )
32
+ datetime2 = datetime .strptime (str (result_time ),"%H:%M:%S" )
33
+ saved_time = datetime1 - datetime2 # subracting to find saved time
34
+ return str (result_time ), str (saved_time )
35
+
36
+
37
+
38
+ print (Calculate_result_time_and_saved_time (time1 ,speed ))
0 commit comments