File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/bin/python3
2+
3+ import math
4+ import os
5+ import random
6+ import re
7+ import sys
8+
9+ #
10+ # Complete the 'plusMinus' function below.
11+ #
12+ # The function accepts INTEGER_ARRAY arr as parameter.
13+ #
14+
15+ def plusMinus (arr ):
16+ # Write your code here
17+ size_of_arr = len (arr )
18+ zero_numbers = 0
19+ pos_numbers = 0
20+ neg_numbers = 0
21+
22+ if size_of_arr == 0 :
23+ return
24+
25+ for x in arr :
26+ if x == 0 :
27+ zero_numbers += 1
28+ elif x > 0 :
29+ pos_numbers += 1
30+ else : # x<0
31+ neg_numbers += 1
32+
33+ pos_ratios = pos_numbers / size_of_arr
34+ neg_ratios = neg_numbers / size_of_arr
35+ zero_ratios = zero_numbers / size_of_arr
36+
37+ print ("{:.6f}" .format (pos_ratios ))
38+ print ("{:.6f}" .format (neg_ratios ))
39+ print ("{:.6f}" .format (zero_ratios ))
40+
41+ return None
42+
43+ if __name__ == '__main__' :
44+ n = int (input ().strip ())
45+
46+ arr = list (map (int , input ().rstrip ().split ()))
47+
48+ plusMinus (arr )
Original file line number Diff line number Diff line change 1+ #!/bin/python3
2+
3+ import math
4+ import os
5+ import random
6+ import re
7+ import sys
8+
9+ #
10+ # Complete the 'miniMaxSum' function below.
11+ #
12+ # The function accepts INTEGER_ARRAY arr as parameter.
13+ #
14+
15+ def miniMaxSum (arr ):
16+ # Write your code here
17+ if len (arr ) != 5 :
18+ return
19+ '''
20+ sorted_arr = sorted(arr)
21+ min_sum = sum(sorted_arr[:4])
22+ max_sum = sum(sorted_arr[1:])
23+ '''
24+ arr .sort ()
25+ min_sum = sum (arr [:4 ])
26+ max_sum = sum (arr [1 :])
27+ print (f'{ min_sum } { max_sum } ' )
28+
29+
30+ if __name__ == '__main__' :
31+
32+ arr = list (map (int , input ().rstrip ().split ()))
33+
34+ miniMaxSum (arr )
Original file line number Diff line number Diff line change 1+ #!/bin/python3
2+
3+ import math
4+ import os
5+ import random
6+ import re
7+ import sys
8+ from datetime import datetime
9+
10+ #
11+ # Complete the 'timeConversion' function below.
12+ #
13+ # The function is expected to return a STRING.
14+ # The function accepts STRING s as parameter.
15+ #
16+
17+ def timeConversion (s ):
18+ # Write your code here
19+ str_datetime = datetime .strptime (s , '%H:%M:%S%p' )
20+ return (f'{ str_datetime .hour } :{ str_datetime .minute } :{ str_datetime .second } ' )
21+
22+ if __name__ == '__main__' :
23+ s = input ()
24+
25+ result = timeConversion (s )
26+
27+ print (result )
Original file line number Diff line number Diff line change 1+ #!/bin/python3
2+
3+ import math
4+ import os
5+ import random
6+ import re
7+ import sys
8+ '''
9+ 12:01:00PM -> 12:01:00
10+ 01:01:00PM -> 13:01:00
11+ 11:59:59PM -> 23:59:59
12+
13+ 12:01:00AM -> 00:01:00
14+ 01:01:00AM -> 01:01:00
15+ 11:59:59AM -> 11:59:59
16+ '''
17+
18+
19+
20+ def timeConversion (s ):
21+ # Write your code here
22+ new_time = ''
23+ new_hour = 0
24+ if s [- 2 ] == 'P' and s [0 :2 ]!= '12' :
25+ new_hour = int (s [0 :2 ]) + 12
26+ new_time = str (new_hour ) + s [2 :- 2 ]
27+ print (new_hour , new_time )
28+
29+ elif s [- 2 ] == 'A' and s [0 :2 ]== '12' :
30+ new_time = '00' + s [2 :- 2 ]
31+
32+ else :
33+ new_time = s [:- 2 ]
34+
35+ return (new_time )
36+
37+
38+ if __name__ == '__main__' :
39+ s = input ()
40+
41+ result = timeConversion (s )
42+
43+ print (result )
You can’t perform that action at this time.
0 commit comments