Skip to content

Commit c4bb514

Browse files
committed
adding more code
1 parent c508905 commit c4bb514

9 files changed

Lines changed: 127 additions & 0 deletions

File tree

arrays/equalarry.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
t=int(input())
2+
for i in range(t):
3+
n = int(input())
4+
lt = []
5+
for i in range(0, n):
6+
lt.append(int(input()))
7+
8+
9+
10+
mn = min(lt)
11+
12+
13+
14+
sum = 0
15+
16+
for i in lt:
17+
sum += i - mn
18+
19+
print(sum)
20+
21+
22+
23+

arrays/evenodd.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
def even_odd(n):
2+
if n%2 == 0:
3+
print("given number is even")
4+
else:
5+
print("given number is odd")
6+
7+
return n
8+
n = int(input("enter the value"))
9+
print(even_odd(n))

arrays/hollow_square.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def hollow_square(n, m):
2+
k = []
3+
for i in range(n):
4+
k.append(n )
5+
for i in range(m):
6+
k.append("*"*m)
7+
8+
9+
return k
10+
11+
12+
13+
14+
15+
print(hollow_square(3, 3))
16+

arrays/increasingpattern.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def generate_triangle(n):
2+
"""
3+
Function to return a right-angled triangle of '*' of side n as a list of strings.
4+
5+
Parameters:
6+
n (int): The height and base of the triangle.
7+
8+
Returns:
9+
list: A list of strings where each string represents a row of the triangle.
10+
"""
11+
# Your code here
12+
k = []
13+
for i in range(1, n+1):
14+
k.append("*" * i)
15+
16+
return k
17+
18+
19+
print(generate_triangle(3))

arrays/line.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
my_set = {1, 2, 3, 4, 5, 6, 8, 9, 8}
2+
3+
print(my_set)
4+
dup = int(input("enter dup"))
5+
if dup in my_set:
6+
print("yes it is present")
7+
8+
else:
9+
print("no!")
10+

arrays/multiplepara.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def multiplepara(a, b):
2+
print(a + b)
3+
print(a - b)
4+
print(a * b)
5+
print(a / b)
6+
7+
8+
a = int(input("enter the two values"))
9+
b = int(input("enter the two values"))
10+
print(multiplepara(a, b))

arrays/rotate.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def rotateArr(lt):
2+
while i < j:
3+
lt[j], lt[i] = lt[i], lt[j]
4+
i +=1
5+
j -= 1
6+
return lt
7+
8+
9+
10+
11+
12+
13+
n = int(input("enter the n:"))
14+
k = int(input("enter the k:"))
15+
lt = []
16+
j = n-1
17+
i = 0
18+
for i in range(0, n):
19+
lt.append(int(input()))
20+
21+
print(rotateArr(lt))
22+

arrays/spanstocks.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
def max_profit(prices):
2+
min_price = float('inf') # बहुत बड़ा नंबर (infinity)
3+
max_profit = 0 # शुरुआत में लाभ 0 होगा
4+
5+
6+
return min_price
7+
8+
# उदाहरण (Example)
9+
prices = [7, 10, 1, 3, 6, 9, 2]
10+
print(max_profit(prices)) # आउटपुट: 8

arrays/square.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def generate_square(n):
2+
for i in range(n):
3+
print("*" * n )
4+
return [generate_square]
5+
6+
7+
n = int(input("enter n : "))
8+
print(generate_square(n))

0 commit comments

Comments
 (0)