easy level practice prgms
easy level practice prgms
Write a python program to Find the Smallest and the Largest List
Elements.
Sol:
res_list = []
O/P:
Sol:
def checkPrime(num):
if num < 2:
return 0
else:
x = num // 2
if num % j == 0:
return 0
return 1
a, b = 1, 100
if checkPrime(i):
O/p:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Sol:
num = 25
sqrt_num = int(num**0.5)
if sqrt_num**2==num:
else:
Sol:
if (i*(.5) == int(i*(.5))):
print(i, end=" ")
l=1
r = 100
perfectSquares(l, r)
Output:1 4 9 16 25 36 49 64 81 100
Sol:
sum = 0
temp = num
digit = temp % 10
sum += digit ** 3
temp //= 10
if num == sum:
else:
o/p:
Sol:
lower = 1
upper = 100
# order of number
order = len(str(num))
# initialize sum
sum = 0
temp = num
digit = temp % 10
temp //= 10
if num == sum:
print(num)
O/P:
8
9
Sol:
sum=0
num=int(input("Enter a number:"))
temp=num
while(num):
i=1
fact=1
rem=num%10
while(i<=rem):
fact=fact*i
i=i+1
sum=sum+fact
num=num//10
if(sum==temp):
else:
Enter a number:145
Given number is a strong number
Sol:
year = 2020
else:
Sol:
num = 110
binary_val = num
decimal_val = 0
base = 1
rem = num % 10
num = num // 10
base = base * 2
Decimal Number is 6
10.Convert Decimal to Binary
Sol:
def DecimalToBinary(num):
if num >= 1:
DecimalToBinary(num // 2)
if __name__ == '__main__':
dec_val = 24
DecimalToBinary(dec_val)
O/P: 011000
Sol:
import math
return (x * y) // math.gcd(x, y)
print(my_lcm(6, 4))
O/P:
12
Sol:
num = 1234
reversed_num = 0
while num != 0:
digit = num % 10
num //= 10
o/p: 4321
Sol:
def getSum(n):
sum = 0
sum += int(digit)
return sum
n = 12345
print(getSum(n))
o/p:15
Sol:
num = 3452
count = 0
while num != 0:
num //= 10
count += 1
Sol: num = 16
if num < 0:
else:
sum = 0
sum += num
num -= 1
sol:
Sol:
vowels = 'aeiouAEIOU'
consonants = 'bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ'
vowel_count = 0
consonant_count = 0
if char in vowels:
vowel_count += 1
consonant_count += 1
print(f"Vowels: {vowel_count}")
print(f"Consonants: {consonant_count}")
O/P: Vowels: 4
Consonants: 11
[4, 5, 6],
[7, 8, 9]])
[6, 5, 4],
[3, 2, 1]])
result_matrix = np.add(matrix1, matrix2)
print(result_matrix)
[10 10 10]
[10 10 10]]
Sol:
[3, 4]]
[7, 8]]
[0, 0]]
for i in range(len(matrix1)):
for j in range(len(matrix2[0])):
for k in range(len(matrix2)):
print("Result Matrix:")
print(row)
[19, 22]
[43, 50]
20. Transpose of a Matrix.
Sol:
X = [[12,7],
[4 ,5],
[3 ,8]]
result = [[0,0,0],
[0,0,0]]
for i in range(len(X)):
for j in range(len(X[0])):
result[j][i] = X[i][j]
for r in result:
print(r)
O/P: [12, 4, 3]
[7, 5, 8]