Documente Academic
Documente Profesional
Documente Cultură
Diagonal Difference
1. #!/bin/python3
2.
3. import math
4. import os
5. import random
6. import re
7. import sys
8.
9. #
10. # Complete the 'diagonalDifference' function below.
11. #
12. # The function is expected to return an INTEGER.
13. # The function accepts 2D_INTEGER_ARRAY arr as parameter.
14. #
15.
16. def diagonalDifference(arr):
17. prim = 0
18. sec = 0
19. length = len(arr[0])
20. for count in range(length):
21. prim += arr[count][count]
22. sec += arr[count][(length-count-1)]
23. return abs(prim-sec)
24.
25.
26.
27. if __name__ == '__main__':
28. fptr = open(os.environ['OUTPUT_PATH'], 'w')
29.
30. n = int(input().strip())
31.
32. arr = []
33.
34. for _ in range(n):
35. arr.append(list(map(int, input().rstrip().split())))
36.
37. result = diagonalDifference(arr)
38.
39. fptr.write(str(result) + '\n')
40.
41. fptr.close()
Plus Minus
1. #!/bin/python3
2.
3. import math
4. import os
5. import random
6. import re
7. import sys
8.
9. # Complete the plusMinus function below.
10. def plusMinus(arr):
11. pos = 0
12. neg = 0
13. zero = 0
14.
15. for i in range(len(arr)):
16. if arr[i] > 0:
17. pos += 1
18. elif arr[i] < 0:
19. neg += 1
20. else:
21. zero +=1
22.
23. l = print(pos/len(arr))
24. m = print(neg/len(arr))
25. n = print(zero/len(arr))
26.
27. return(l,m,n)
28.
29. if __name__ == '__main__':
30. n = int(input())
31.
32. arr = list(map(int, input().rstrip().split()))
33.
34. plusMinus(arr)