Lab 7
def rainbow(n):
rainBow = {0:"Violet",1:"Indigo",2:"Blue",3:"Green",4:"Yellow",5:"Orange",6:"Red"}
return rainBow[n]
n = int(input("Enter the number (0-6) :"))
print(n, "represents the",rainbow(n),"color of rainbow")
def p2(l,n):
if n in l:
print("The number",n,"is present",l.count(n),"times in the array.")
else:
print("The number",n,"is not present in the array.")
l = []
for i in range(1,16):
print("Enter the number",i,":",end='')
a = int(input())
l.append(a)
n = int(input("Enter the number to search :"))
p2(l,n)
def p3(l):
neg = 0
pos = 0
eve = 0
odd = 0
for i in l:
if i< 0:
neg += 1
elif i > 0:
pos += 1
else:
pass
if i%2 == 0 :
eve +=1
else:
odd += 1
print("There are",neg,"negative numbers",pos,"positive numbers",eve,"even numbers",odd,"odd numbers in the list.")
l = []
for i in range(1,16):
print("Enter the number",i,":",end='')
a = int(input())
l.append(a)
p3(l)
def lst(list1, list2):
l = list1 + list2
l.sort()
print(l)
l1 = eval(input("Enter the array 1 :"))
l2= eval(input("Enter the array 2 :"))
lst(l1,l2)
def add(m1,m2):
mat = []
for i in range(3):
row = []
for j in range(3):
c = m1[i][j] + m2[i][j]
row.append(c)
mat.append(row)
print(mat)
def multi(m1,m2):
mat = []
for i in range(3):
row = []
s = 0
for j in range(3):
c = m1[i][j] * m2[j][i]
s += c
print(s)
row.append(s)
mat.append(row)
print(mat)
mat1 = [[2, 4, 6], [1, 3, 5], [7, 1, 6]]
mat2 = [[1, 3, 7], [7, 4, 5], [8, 9, 2]]
'''for i in range(1,3):
for j in range(1,4):
row = []
for k in range(1,4):
print("Enter the element",k,"of row",j,"of matrix",i,":",end="")
a = int(input(""))
row.append(a)
if i == 1:
mat1.append(row)
else:
mat2.append(row)'''
print(mat1)
print(mat2)
#add(mat1,mat2)
multi(mat1,mat2)
def dist(x1,y1,x2,y2):
d = ((x2-x1)**2 + (y2-y1)**2)**(1/2)
return d
l = []
for i in range(1,11):
print("Enter the coordinates of point",i,", separated by comma :",end ='')
x,y = eval(input())
c = [x,y]
l.append(c)
print(dist(l[0][0],l[0][1],l[9][0],l[9][1]))
def D(lst):
l =[]
for i in range(len(lst)-1):
a = lst[i+1]-lst[i]
l.append(a)
return l
seq = eval(input("Enter the list of the sequcence in the list format :"))
D1 = D(seq)
D2 = D(D1)
D3 = D(D2)
print(D1)
print(D2)
print(D3)
def Drag(CD,A,p,V):
F = (CD*A*p*(V**2))/2
print(F)
CD = float(input("Enter the drag coeeficient (CD) :"))
A = float(input("Enter the projected area of vehicle perpendicular to the velocity vector (A) :"))
p = 1.23
for V in range(0,41,5):
Drag(CD,A,p,V)
def freq(L):
unit = []
for i in L :
if i not in unit:
print(i,"occurs", L.count(i),"times in data")
unit.append(i)
lst = eval(input("Enter the list :"))
freq(lst)