Sei sulla pagina 1di 2

1.

import math

b=[65, 38, 98, 78.09, 1.8E-4, math.sin(math.degrees(90)), math.cos(5)]

def minimum(a):

return(a[0])

def maximum(a):

a.sort()

return(a[len(a)-1])

fil1=open("compare.txt",'w')

a1=str(maximum(b))+'\n'+str(minimum(b))+"\n"

fil1.write(a1)

fil1.close()

fil1=open("compare.txt",'r')

lines=fil1.readlines()

fil1.close()

lst=[]

for a1 in lines:

lst.append(float(a1))

fil1=open("compare.txt",'a')

fil1.write(str(1/lst[0])+"\n")

fil1.write(str(1/lst[1])+"\n")

fil1.close()

2.

large=int(input("Enter the maximum range of prime number: "))

lst1=[]

for val in range(0, large + 1):

if val > 1:

for n in range(2, val//2 + 2):

if (val % n) == 0:

break
else:

if n == val//2 + 1:

lst1.append(val)

print("Second largest prime Number: "+str(lst1[len(lst1)-2]))

3.

import numpy as np

a=[[4,2,3],[6,4,9],[0,3,8]]

b="Determinant of Matrix is "+ str(np.linalg.det(a))+"\n"

b=b+"Principle Diagonal Matrix "+str(np.diagonal(a))+"\n"

if(np.linalg.det(a)>0):

b=b+"Matrix is not Singular"

else:

b=b+"Matrix is Singular"

fl1=open("matrix.txt",'w')

fl1.write(b)

fl1.close()

Potrebbero piacerti anche