Skip to content

Commit 7ab7c76

Browse files
author
Sagar Paul
committed
practie
1 parent 0cd53a5 commit 7ab7c76

14 files changed

+184
-0
lines changed

Python Problem Solving/13_.py

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'''
2+
55555
3+
4444
4+
333
5+
22
6+
1
7+
'''
8+
9+
for i in range(5,0,-1):
10+
print(str(i)*i)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'''
2+
1 2 3 4 5
3+
1 2 3 4
4+
1 2 3
5+
1 2
6+
1
7+
'''
8+
9+
n = int(input("type the number: "))
10+
for row in range(1,n+1):
11+
for col in range(1,n+2-row):
12+
print(col, end=" ")
13+
print()
14+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Program To Check Entered Number is Prime or Not
2+
3+
n = int(input("input a number to check wheather it is prime or not: "))
4+
if n>=1:
5+
if n==1:
6+
print("1 is NOT PRIME Number")
7+
else:
8+
for i in range(2,n):
9+
if n%i ==0:
10+
print(f"The number {n} is NOT a PRIME number")
11+
break
12+
else:
13+
print(f"The number {n} is a PRIME number")
14+
else:
15+
print(f"The number {n} is NOT a PRIME number")
16+
17+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
n = int(input("type the number upto which you wanna find PRIME number: "))
2+
a = []
3+
if n>1:
4+
for i in range(2,n+1):
5+
for j in range(2,i):
6+
if i%j ==0:
7+
break
8+
else:
9+
a.append(i)
10+
print(a)
11+
12+
13+
14+
15+
16+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'''
2+
*
3+
* *
4+
* *
5+
*******
6+
'''
7+
n = int(input("Type how many rows you want: "))
8+
for row in range(1,n+1):
9+
for col in range(1,2*n):
10+
if row ==n or col - row == n-1 or col + row == n+1 :
11+
print("*", end="")
12+
else:
13+
print(end=" ")
14+
print()
15+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
*
3+
* *
4+
* *
5+
* * * *
6+
'''
7+
8+
n = int(input("Type no. of rows: "))
9+
for row in range(1,n+1):
10+
for col in range(1,2*n):
11+
if row == n :
12+
if col%2 !=0:
13+
print("*",end="")
14+
else:
15+
print(end=" ")
16+
elif row + col == n+1 or col -row == n-1 :
17+
print("*",end="")
18+
else:
19+
print(end=" ")
20+
print()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Perfect Numbers: a number is called perfect number if the sum of all divisors of the number excluding that number
2+
# Example: 6 = 1+ 2 + 3 ---> 6 is perfect number
3+
# 4 != 1 + 2 ---> 4 is not a perfect number
4+
5+
n = int(input("Type the number: "))
6+
sum = 0
7+
for i in range(1,n):
8+
if n%i ==0:
9+
sum = i + sum
10+
else:
11+
None
12+
13+
if sum == n:
14+
print(f"the number {n} is PERFECT number")
15+
else:
16+
print(f"the number {n} is NOT PERFECT number")
17+
18+
19+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#Program to Print Perfect Numbers in Given Interval
2+
3+
upper = int(input("Type the upper number here: "))
4+
lower = int(input("Type the lower number here: "))
5+
6+
print(f"The perfect numbers in range[{lower},{upper}] are : ")
7+
8+
for num in range(lower, upper+1):
9+
sum = 0
10+
for j in range(1,num):
11+
if num%j ==0:
12+
sum = sum +j
13+
if sum ==num :
14+
print(num)
15+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
a = int(input("a = "))
2+
b =int(input("b = "))
3+
4+
temp = a
5+
a = b
6+
b = temp
7+
8+
print("After swaping values of a and b")
9+
10+
print(f"a = {a}")
11+
print(f"b = {b}")
12+

0 commit comments

Comments
 (0)