Skip to content

Commit 822a0ca

Browse files
Coding init
1 parent d269dc9 commit 822a0ca

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

Coding/Diagonal.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
a = [[11,2,4] , [4,5,6] , [10,8,-12]]
2+
n = len(a)
3+
4+
diagonal_1 = diagonal_2 = 0
5+
6+
7+
for i,j in zip(range(0,n), range(n-1,-1,-1)):
8+
#print("i={},j={}".format(i,j))
9+
#print(a[i][i])
10+
#print(a[i][j])
11+
diagonal_1 = diagonal_1 + a[i][i]
12+
diagonal_2 = diagonal_2 + a[i][j]
13+
14+
print(abs(diagonal_1 - diagonal_2))
15+
#print(diagonal_1)
16+
#print(diagonal_2)

Coding/Fraction.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
# Complete the plusMinus function below.
3+
def plusMinus(arr):
4+
arr_len = len(arr)
5+
positive = negative = zero = 0.00
6+
for i in range(arr_len):
7+
if arr[i] >0:
8+
positive = positive + 1
9+
elif arr[i]<0:
10+
negative = negative + 1
11+
else :
12+
zero = zero + 1
13+
positive = positive / arr_len
14+
negative = negative / arr_len
15+
zero = zero / arr_len
16+
17+
print('{0:.4f}'.format(positive))
18+
print('{0:.4f}'.format(negative))
19+
print('{0:.4f}'.format(zero))
20+
21+
22+
if __name__ == '__main__':
23+
n = int(input())
24+
25+
arr = list(map(int, input().rstrip().split()))
26+
27+
plusMinus(arr)

Coding/Staircase.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/python3
2+
3+
import math
4+
import os
5+
import random
6+
import re
7+
import sys
8+
9+
# Complete the staircase function below.
10+
def staircase(n):
11+
count=n
12+
for i in range(n):
13+
for j in range(n):
14+
if j>=count-1:
15+
sys.stdout.write("#")
16+
else:
17+
sys.stdout.write(" ")
18+
count=count-1
19+
sys.stdout.write("\n")
20+
21+
if __name__ == '__main__':
22+
n = int(input())
23+
24+
staircase(n)

0 commit comments

Comments
 (0)