Skip to content

Commit 9c3e0ed

Browse files
authored
Add files via upload
1 parent ba4b5b9 commit 9c3e0ed

24 files changed

Lines changed: 438 additions & 0 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
A = [[1,2,3],
2+
[4,5,6],
3+
[7,8,9]]
4+
5+
B = [[9,8,7],
6+
[6,5,4],
7+
[3,2,1]]
8+
9+
import numpy as np
10+
A = np.array(A)
11+
B = np.array(B)
12+
13+
pdkt = np.dot(A,B)
14+
print(pdkt)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### Core logic:
2+
3+
# An Armstrong number is a number that is equal to the sum of its own digits each raised to the power of the number of digits.
4+
5+
# For example:
6+
7+
# 153 = 1³ + 5³ + 3³ = 153 (Armstrong number)
8+
# 120 ≠ 1³ + 2³ + 0³ = 9 (Not an Armstrong number)
9+
10+
x = int(input("Enter the number"))
11+
temp = x
12+
rev = 0
13+
power = len(str(x))
14+
15+
while x > 0:
16+
d = x % 10
17+
rev = rev + (d ** power)
18+
x = x //10
19+
20+
if temp == rev:
21+
print(f"{temp} is Armstrong number")
22+
else:
23+
print(f"{temp} is not Armstrong number")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
a = str(input("Enter first string: "))
2+
b = str(input("Enter second string: "))
3+
a1 = set(a) # convert string to set why? to get unique letters
4+
b1 = set(b) # convert string to set why? to get unique letters
5+
print(a1)
6+
print(b1)
7+
c = a1 & b1 # intersection why? to get common letters
8+
print(c)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
lst = [1, 2, 2, 3, 4, 1, 2, 5, 5, 5,23, 34, 34, 23, 1]
2+
3+
freq = {} # empty dictionary to store frequency
4+
5+
6+
for i in lst: # iterate through each element in the list
7+
if i in freq: # check if element already in dictionary
8+
freq[i] += 1 # increment count if found
9+
else:
10+
freq[i] = 1 # initialize count if not found
11+
12+
print("Frequency Dictionary:", freq)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
### Core logic: Digit frequency is found by iterating through each digit and incrementing a counter when a match is found.
2+
3+
## Single digit count
4+
5+
# x = input("Enter the number:" )
6+
# digit = input("Enter the digit to be counted: ")
7+
# count = 0
8+
9+
# for i in x:
10+
# if i == digit:
11+
# count+= 1
12+
# print(f"The digit frequency of {digit} in {x} is:" ,count)
13+
14+
###########################################
15+
16+
## All digit frequency count
17+
18+
x = input("Enter the number: ")
19+
20+
freq = {} # empty dictionary to store frequency
21+
22+
for d in x: # iterate through each digit in the number
23+
if d in freq: # check if digit already in dictionary
24+
freq[d] += 1 # increment count if found
25+
else:
26+
freq[d] = 1 # initialize count if not found
27+
28+
print("Digit Frequency Dictionary:", freq)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
### Core logic: Factorial is computed using iterative multiplication from 1 to n
2+
3+
x = int(input("Enter a number to find factorial: "))
4+
fact = 1
5+
for i in range(1, x+1):
6+
fact = fact * i
7+
print(f"The factorial of {x} is:", fact)
8+
9+
10+
## Math opearator based
11+
12+
# import math
13+
# x = int(input("Enter number: "))
14+
# print(math.factorial(x))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Core logic: To print the Fibonacci sequence in Python, we need to generate a series of numbers where each number is the sum of the two preceding ones, starting from 0 and 1. The Fibonacci sequence follows a specific pattern that begins with 0 and 1, and every subsequent number is the sum of the two previous numbers.
2+
3+
# Mathematically, the Fibonacci sequence can be represented as:
4+
5+
# F(n) = F(n-1) + F(n-2)
6+
7+
# Where:
8+
# F(0) = 0
9+
# F(1) = 1
10+
# F(n) for n > 1 is the sum of the two preceding numbers.
11+
12+
### Recursion
13+
14+
# def fib(n):
15+
# if n <= 1:
16+
# return n
17+
# return fib(n-1) + fib(n-2)
18+
# print(fib(10))
19+
20+
n = int(input("Enter till when you want the series:"))
21+
a = 0
22+
b =1
23+
next =b
24+
count = 1
25+
while count <= n:
26+
print(next, end = " ") #👉 prints current Fibonacci number
27+
count = count + 1 # 👉 keeps track of how many numbers printed - Increase the counter
28+
a, b = b, next # It moves the sequence forward
29+
next = a + b # 👉 next fibonacci number = sum of previous two numbers
30+
print()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# addition = lambda a, b: a + b
2+
# print(addition(3, 5)) # Returns 8
3+
4+
5+
### Even and odd
6+
7+
# def even(num):
8+
# if num % 2 == 0:
9+
# print("Even")
10+
# else:
11+
# print("Odd")
12+
# even(25)
13+
14+
# even_1 = lambda a: a % 2 == 0
15+
# print(even_1(22))
16+
17+
18+
addition_1 = lambda x,y,z : x+y+z
19+
print(addition_1(2,3,4))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ## Core logic:
2+
3+
# ## GCD (Greatest Common Divisor) and LCM (Least Common Multiple) of two numbers are calculated using mathematical algorithms.
4+
5+
# GCD is computed using the Euclidean algorithm by repeatedly replacing (a, b) with (b, a mod b) until b becomes zero.
6+
7+
# LCM:
8+
9+
# LCM is calculated using the relationship: LCM(a, b) = (a × b) / GCD(a, b).
10+
11+
def gcd (a,b):
12+
while b != 0:
13+
a,b = b, a%b
14+
return a
15+
x = int(input("Enter the first number: "))
16+
y = int(input("Enter the second number: "))
17+
print("GCD:",gcd(x,y))
18+
19+
def lcm(a, b):
20+
return (a * b) // gcd(a, b)
21+
22+
print("LCM:",lcm(x,y))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
list_a = [1,2,3,4,5,6,7,8]
2+
3+
#sqr = lambda i : i * i
4+
5+
#for i in list_a:
6+
#print(sqr(i))
7+
8+
#print(list(map(sqr,list_a)))
9+
10+
# cube = lambda x: x ** 3
11+
# for x in list_a:
12+
# if x % 2 == 0:
13+
# print(cube(x))
14+
# else:
15+
# continue
16+
17+
#### Dictionary mapping
18+
19+
sqr_dict = {x: x**2 for x in list_a}
20+
for x in list_a:
21+
if x % 2 == 0:
22+
print(sqr_dict[x])
23+
else:
24+
continue
25+
26+
#print(sqr_dict)
27+

0 commit comments

Comments
 (0)