Skip to content

Commit ef5a07e

Browse files
author
Sagar Paul
committed
Python Practice Problems
1 parent 7ab7c76 commit ef5a07e

25 files changed

+503
-4
lines changed

Python Problem Solving/02.py

Whitespace-only changes.

Python Problem Solving/10_Floyd's Triangle | Printing Numbers in Right Triangle Shape.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
num = num +1
1616
print()
1717

18+

Python Problem Solving/24_Printing Stars in Pyramid Shape Using while loop.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
'''
2-
*
3-
* *
4-
* * *
5-
* * * *
2+
*
3+
* *
4+
* * *
5+
* * * *
6+
* * * * *
7+
* * * * * *
8+
* * * * * * *
69
'''
710
n = int(input("enter no. of rows: "))
811
i = 1
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,32 @@
1+
'''
2+
*
3+
* *
4+
* *
5+
* *
6+
*
17
28
9+
# for 5 rows and 5 columns
310
11+
for row in range(5):
12+
for col in range(5):
13+
if row + col ==2 or row - col == 2 or col - row ==2 or col+row ==6:
14+
print("*",end="")
15+
else:
16+
print(end=" ")
17+
print()
418
19+
'''
20+
21+
# for 7 rows and 7 columns
22+
23+
for row in range(7):
24+
for col in range(7):
25+
if row +col == 3 or row-col==3 or col-row ==3 or row +col==9:
26+
print("*",end="")
27+
else:
28+
print(end=" ")
29+
print()
530

631

732

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def reverse(string):
2+
rev_string = ""
3+
for i in string:
4+
rev_string = i + rev_string
5+
print(rev_string)
6+
7+
string = input("--->>")
8+
reverse(string)

Python Problem Solving/27_Printing Numbers in Square Shape.py

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def computeGCD(a,b):
2+
if b ==0:
3+
return a
4+
else:
5+
return computeGCD(b, a%b)
6+
7+
a = int(input("a = "))
8+
b = int(input("b = "))
9+
10+
print(computeGCD(a,b))
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Program To Find out the GCD of Two Positive Numbers
2+
import math
3+
4+
x = int(input("x = "))
5+
y = int(input("y = "))
6+
7+
z = math.gcd(x,y)
8+
9+
print(f"Highest common factor or GCD of {x} and {y} is: {z}")
10+
11+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'''
2+
1
3+
2 1 2
4+
3 2 1 2 3
5+
4 3 2 1 2 3 4
6+
5 4 3 2 1 2 3 4 5
7+
6 5 4 3 2 1 2 3 4 5 6
8+
7 6 5 4 3 2 1 2 3 4 5 6 7
9+
8 7 6 5 4 3 2 1 2 3 4 5 6 7 8
10+
9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9
11+
10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10
12+
11 10 9 8 7 6 5 4 3 2 1 2 3 4 5 6 7 8 9 10 11
13+
'''
14+
15+
n = int(input("Enter Number of rows: "))
16+
17+
for row in range(1,n+1):
18+
for i in range(1,n-row+1):
19+
print(format(" ","<3"),end="")
20+
for j in range(row,0,-1):
21+
print(format(j,"<3"),end="")
22+
for k in range(2,row+1):
23+
print(format(k,"<3"),end="")
24+
print()
25+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'''
2+
1
3+
2 3
4+
4 5 6
5+
7 8 9 10
6+
11 12 13 14 15
7+
16 17 18 19 20 21
8+
'''
9+
10+
11+
row = int(input("Enter Number: "))
12+
13+
n =1
14+
for i in range(1,row+1):
15+
for j in range(1,i+1):
16+
print(n,end=" ")
17+
n = n+1
18+
print()
19+
20+
21+
22+

0 commit comments

Comments
 (0)