Python Programming Jagesh Soni
Python Programming Jagesh Soni
SUBMITTED BY:
JAGESH SONI
CSE 2ND YEAR
1805210023
SUBMITTED TO:
MS. PRATHIBHA PANDEY
import sys
A = [[12, 7, 3],
[4, 5, 6],
[7, 8, 9]]
B = [[5, 8, 1, 2],
[6, 7, 3, 0],
[4, 5, 9, 1]]
# iterating by row of A
for i in range(len(A)):
# iterating by column by B
for j in range(len(B[0])):
# iterating by rows of B
for k in range(len(B)):
result[i][j] += A[i][k] * B[k][j]
for r in result:
print(r)
def hcf(a,b):
if(b==0):
return a
else:
return hcf(b,a%b)
a = 60
b= 48
with open(fname,'r') as f:
contents=f.read()
words=content.split()
for i in range(len(words)):
for j in range(len(words)):
if(words[i]==words[j]):
count+=1
else:
count=count
if(count==maxcount):
l.append(words[i])
elif(count>maxcount):t
l.clear()
l.append(words[i])
maxcount=count
else:
l=l
count=0
print(l)
5.) Python program to find the square root of a number(Newton’s
method)
def squareRoot(n, l) :
while (1) :
count += 1;
# Update root
x = root;
return root;
if __name__ == "__main__" :
n = 327;
l = 0.00001;
print(squareRoot(n, l));
6.) Python program for exponentiation(power of a number)
arr = ['p','y','t','h','o','n']
x = 'a'
print("element found at index "+str(linearsearch(arr,x)))
else:
# Element is not present in the array
return -1
# Test array
arr = [ 2, 3, 4, 10, 40 ]
x = 10
# Function call
result = binary_search(arr, 0, len(arr)-1, x)
if result != -1:
print("Element is present at index", str(result))
else:
print("Element is not present in array")
10.)Python program to perform selection sort
import sys
A = [64, 25, 12, 22, 11]
key = arr[i]
mergeSort(arr,0,n-1)
print ("\n\nSorted array is")
for i in range(n):
print ("%d" %arr[i]),
# Driver code
N = 100;
print_first_N_primes(N);
14.) Python program to simulate bouncing ball in pygame
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Bouncing ball")
ball = pygame.image.load("ball.jpg")
ballrect = ball.get_rect()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
ballrect = ballrect.move(speed)
if ballrect.left < 0 or ballrect.right > width:
speed[0] = -speed[0]
if ballrect.top < 0 or ballrect.bottom > height:
speed[1] = -speed[1]
screen.fill(background)
screen.blit(ball, ballrect)
pygame.display.flip()