diff --git a/Task/Sumanta Kumar Dutta/Q1.py b/Task/Sumanta Kumar Dutta/Q1.py new file mode 100644 index 0000000..e67357f --- /dev/null +++ b/Task/Sumanta Kumar Dutta/Q1.py @@ -0,0 +1,25 @@ +#Given two strings s and t, return true if t is an anagram of s, and false otherwise. +#An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. + +#Function to arrange the strings in alphabetical order +def alpha(a): + st = "" + for i in range(97,123): + for j in a: + if(j == chr(i)): + st = st + j + return st + +s = input("Enter the string s: ") +t = input("Enter the string t: ") +flag = False + +if(1<=len(s) and 1<=len(t) and len(s)<=(5*104) and len(t)<=(5*104) and s.isalpha()==True and s.islower()==True and t.isalpha()==True and t.islower()==True): + if(len(s)!=len(t)): + flag = False + else: + if(alpha(s)==alpha(t)): + flag = True + print(flag) +else: + print("Invalid input") diff --git a/Task/Sumanta Kumar Dutta/Q10.py b/Task/Sumanta Kumar Dutta/Q10.py new file mode 100644 index 0000000..4441b4d --- /dev/null +++ b/Task/Sumanta Kumar Dutta/Q10.py @@ -0,0 +1,51 @@ +#Given a 2D integer array matrix, return the transpose of matrix. +#The transpose of a matrix is the matrix flipped over its main diagonal, switching the matrix's row and column indices. + +m = int(input("Enter the number of rows: ")) +n = int(input("Enter the number of columns: ")) + +if(m<1 or n>1000 or (m*n)>105 or (m*n)<1): + print("Invalid input") + exit() + +#Creating the matrix +mat = [] +for i in range(m): + mat.append([]) + +#Initializing the matrix with 0s +for i in range(m): + for j in range(n): + mat[i].append(j) + mat[i][j] = 0 + +#User input +print("Enter the elements:-") +for i in range(m): + for j in range(n): + ip = int(input("Element: ")) + if(ip<-109 or ip>109): + print("Invalid input") + exit() + mat[i][j] = ip + +#Creating the transpose matrix:- +trans = [] +for i in range(n): + trans.append([]) + +#Initializing the transpose matrix with 0s +for i in range(n): + for j in range(m): + trans[i].append(j) + trans[i][j] = 0 + +#Finding transpose +for i in range(n): + for j in range(m): + trans[i][j] = mat[j][i] + +print("Input matrix:", end=" ") +print(mat) +print("Output matrix:", end=" ") +print(trans) diff --git a/Task/Sumanta Kumar Dutta/Q2.py b/Task/Sumanta Kumar Dutta/Q2.py new file mode 100644 index 0000000..944f989 --- /dev/null +++ b/Task/Sumanta Kumar Dutta/Q2.py @@ -0,0 +1,20 @@ +#Suppose you are given a string containing only English alphabets (Uppercase and Lowercase letter both). You have to display the frequency of each character in lexicographical order. + +st = input("Enter a string: ") +chk = "" #Stores all the checked characters + +#Uppercase +for i in range(65,91): + for j in st: + if(j == chr(i)): + if(chk.find(j)==-1): + print(j+"-> "+str(st.count(j))) + chk = chk + j + +#Lowercase +for i in range(97,123): + for j in st: + if(j == chr(i)): + if(chk.find(j)==-1): + print(j+"-> "+str(st.count(j))) + chk = chk + j diff --git a/Task/Sumanta Kumar Dutta/Q3.py b/Task/Sumanta Kumar Dutta/Q3.py new file mode 100644 index 0000000..1583e37 --- /dev/null +++ b/Task/Sumanta Kumar Dutta/Q3.py @@ -0,0 +1,24 @@ +#You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's. +#Increment the large integer by one and return the resulting array of digits. + +n = int(input("Enter the number of digits: ")) +number = [] +no = "" +#Input +for i in range(n): + a = int(input("Enter a digit: ")) + number.append(a) + +#Fetching the number +for i in number: + no = no + str(i) +num = int(no) + +res = num + 1 #Resultant number + +#Output +result = [] +for i in str(res): + result.append(int(i)) + +print(result) diff --git a/Task/Sumanta Kumar Dutta/Q4.py b/Task/Sumanta Kumar Dutta/Q4.py new file mode 100644 index 0000000..6953dd2 --- /dev/null +++ b/Task/Sumanta Kumar Dutta/Q4.py @@ -0,0 +1,49 @@ +#Write a Python script to capture video image from a webcam and differentiate objects of black and white colors by drawing bounding boxes around them using OpenCV. + +import cv2 +import numpy as np + +def checkColour(frame): + hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) + + lower_white = np.array([0, 0, 168]) + upper_white = np.array([172, 111, 255]) + + lower_black = np.array([0, 0, 0]) + upper_black = np.array([360, 255, 50]) + + mask_white = cv2.inRange(hsv, lower_white, upper_white) + mask_black = cv2.inRange(hsv, lower_black, upper_black) + + return mask_white, mask_black + + +cap = cv2.VideoCapture(0) + +while True: + flag, frame = cap.read() + frame = cv2.flip(frame, 1) + if(flag==False): + print("No webcam connected!") + break + + white_mask, black_mask = checkColour(frame) + + contours_white = cv2.findContours(white_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) + contours_black = cv2.findContours(black_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) + + for contour in contours_white[0]: + x, y, w, h = cv2.boundingRect(contour) + cv2.rectangle(frame, (x,y), (x+w, y+h), (255,255,255), 2) + + for contour in contours_black[0]: + x, y, w, h = cv2.boundingRect(contour) + cv2.rectangle(frame, (x,y), (x+w, y+h), (0,0,0), 2) + + cv2.imshow('Video Output', frame) + + if cv2.waitKey(1) == ord('q'): + break + +cap.release() +cv2.destroyAllWindows() diff --git a/Task/Sumanta Kumar Dutta/Q5.py b/Task/Sumanta Kumar Dutta/Q5.py new file mode 100644 index 0000000..3d07f5a --- /dev/null +++ b/Task/Sumanta Kumar Dutta/Q5.py @@ -0,0 +1,13 @@ +#Implement a program to detect edges in an image using the Canny edge detector in OpenCV. + +#Prototype +import cv2 + +img = cv2.imread('mango.jpg', 1) #Demo image for testing +img = cv2.resize(img, (800, 600)) #Resizing our image for convenience + +canny = cv2.Canny(img, 100, 200) + +cv2.imshow('Image',canny) +cv2.waitKey(0) +cv2.destroyAllWindows() diff --git a/Task/Sumanta Kumar Dutta/Q6.py b/Task/Sumanta Kumar Dutta/Q6.py new file mode 100644 index 0000000..72073bc --- /dev/null +++ b/Task/Sumanta Kumar Dutta/Q6.py @@ -0,0 +1,37 @@ +#Given an array, A, of length N. Find the absolute difference between the smallest and largest prime number in array A. + +def isPrime(a): + c = 0 + for i in range(1,a): + if(a%i==0): + c=c+1 + if(c==1): + return True + return False + +n = int(input("Enter the length of the array: ")) +number = [] + +#Input +for i in range(n): + number.append(int(input("Enter a number: "))) +#Displaying the inputs +print(n) +for i in number: + print(i, end =" ") +print() + +number.sort() +for i in number: + if(isPrime(i)==True): + s = i #Smallest prime number + break + +number.sort(reverse=True) +for i in number: + if(isPrime(i)==True): + l = i #Largest prime number + break + +diff = int(l)-s +print(diff) diff --git a/Task/Sumanta Kumar Dutta/Q7.py b/Task/Sumanta Kumar Dutta/Q7.py new file mode 100644 index 0000000..36dcec0 --- /dev/null +++ b/Task/Sumanta Kumar Dutta/Q7.py @@ -0,0 +1,35 @@ +#Alfi asked Roy to go shopping with her. Witty Roy came up with a condition. He said, for each product of MRP (Maximum Retail Price) R, she'll have to pay a minimum +# of all the prime factors of R and he himself will pay the rest of the amount. Without giving it a second thought Alfi agreed. Now they bought N number of products. +#You're to find how much money Roy had to pay for each product. + +def isPrime(a): + c = 0 + for i in range(1,a): + if(a%i==0): + c=c+1 + if(c==1): + return True + return False + + +N = int(input("Enter the number of products: ")) + +if(N<2): + print("Invalid Input") + exit() + +R = [] +for i in range(N): + ip = int(input("Enter the MRPs: ")) + if(ip>1000000): + print("Invalid Input") + exit() + R.append(ip) + +for i in R: + ap = 0 + for j in range(2,i+1): + if(i%j==0 and isPrime(j)==True): + ap = j + break + print(i-ap) diff --git a/Task/Sumanta Kumar Dutta/Q8.py b/Task/Sumanta Kumar Dutta/Q8.py new file mode 100644 index 0000000..55d201b --- /dev/null +++ b/Task/Sumanta Kumar Dutta/Q8.py @@ -0,0 +1,16 @@ +#Develop a Python program to count the frequency of each element in a list and return it as a dictionary. + +n = int(input("Enter the number of elements: ")) +l = [] +for i in range(n): + l.append(input("Enter an element: ")) + +d = {} +chk = [] + +for i in l: + if(chk.count(i)==0): + d[i] = l.count(i) + chk.append(i) + +print(d) diff --git a/Task/Sumanta Kumar Dutta/Q9.py b/Task/Sumanta Kumar Dutta/Q9.py new file mode 100644 index 0000000..ecb2870 --- /dev/null +++ b/Task/Sumanta Kumar Dutta/Q9.py @@ -0,0 +1,30 @@ +#Given a dataset IRIS (CSV file) (download it) and create a dataframe from it. Now change the attributes according to the following information: +#1- S_length to sepal length +#2- S_width to sepal width +#3- P length to petal length +#4-P_width to petal width + +#-Now write a program to find the sum of all lengths of all sepal length in cm. +#Find the index value of maximum and minimum length from petal lengths.(Hint: you can use predefined functions idmax() and idmin()) +#Note: Number of instances is 150 + +import pandas as pd + +#sepal.length, sepal.width, petal.length, petal.width, variety +data = pd.read_csv('iris.csv') #Creating a dataframe from the iris.csv file +data.rename(columns={'sepal.length':'S_length', 'sepal.width':'S_width', 'petal.length':'P_length', 'petal.width':'P_width'}, inplace=True) + +#Finding the sum of all sepal length in cm. +sum = 0.0 +for i in range(150): + s_length = float(data.at[i,'S_length']) + sum = sum + s_length + +print("The sum of all sepal lengths =",end=" ") +print(sum, end=" cm\n\n") + +#Finding the index value of maximum and minimum length from petal lengths +print("The index value of maximum ",end=" ") +print(data[['P_length']].idxmax(), end="\n\n") +print("The index value of minimum ",end=" ") +print(data[['P_length']].idxmin()) diff --git a/Task/Sumanta Kumar Dutta/iris.csv b/Task/Sumanta Kumar Dutta/iris.csv new file mode 100644 index 0000000..1b9d029 --- /dev/null +++ b/Task/Sumanta Kumar Dutta/iris.csv @@ -0,0 +1,151 @@ +"sepal.length","sepal.width","petal.length","petal.width","variety" +5.1,3.5,1.4,.2,"Setosa" +4.9,3,1.4,.2,"Setosa" +4.7,3.2,1.3,.2,"Setosa" +4.6,3.1,1.5,.2,"Setosa" +5,3.6,1.4,.2,"Setosa" +5.4,3.9,1.7,.4,"Setosa" +4.6,3.4,1.4,.3,"Setosa" +5,3.4,1.5,.2,"Setosa" +4.4,2.9,1.4,.2,"Setosa" +4.9,3.1,1.5,.1,"Setosa" +5.4,3.7,1.5,.2,"Setosa" +4.8,3.4,1.6,.2,"Setosa" +4.8,3,1.4,.1,"Setosa" +4.3,3,1.1,.1,"Setosa" +5.8,4,1.2,.2,"Setosa" +5.7,4.4,1.5,.4,"Setosa" +5.4,3.9,1.3,.4,"Setosa" +5.1,3.5,1.4,.3,"Setosa" +5.7,3.8,1.7,.3,"Setosa" +5.1,3.8,1.5,.3,"Setosa" +5.4,3.4,1.7,.2,"Setosa" +5.1,3.7,1.5,.4,"Setosa" +4.6,3.6,1,.2,"Setosa" +5.1,3.3,1.7,.5,"Setosa" +4.8,3.4,1.9,.2,"Setosa" +5,3,1.6,.2,"Setosa" +5,3.4,1.6,.4,"Setosa" +5.2,3.5,1.5,.2,"Setosa" +5.2,3.4,1.4,.2,"Setosa" +4.7,3.2,1.6,.2,"Setosa" +4.8,3.1,1.6,.2,"Setosa" +5.4,3.4,1.5,.4,"Setosa" +5.2,4.1,1.5,.1,"Setosa" +5.5,4.2,1.4,.2,"Setosa" +4.9,3.1,1.5,.2,"Setosa" +5,3.2,1.2,.2,"Setosa" +5.5,3.5,1.3,.2,"Setosa" +4.9,3.6,1.4,.1,"Setosa" +4.4,3,1.3,.2,"Setosa" +5.1,3.4,1.5,.2,"Setosa" +5,3.5,1.3,.3,"Setosa" +4.5,2.3,1.3,.3,"Setosa" +4.4,3.2,1.3,.2,"Setosa" +5,3.5,1.6,.6,"Setosa" +5.1,3.8,1.9,.4,"Setosa" +4.8,3,1.4,.3,"Setosa" +5.1,3.8,1.6,.2,"Setosa" +4.6,3.2,1.4,.2,"Setosa" +5.3,3.7,1.5,.2,"Setosa" +5,3.3,1.4,.2,"Setosa" +7,3.2,4.7,1.4,"Versicolor" +6.4,3.2,4.5,1.5,"Versicolor" +6.9,3.1,4.9,1.5,"Versicolor" +5.5,2.3,4,1.3,"Versicolor" +6.5,2.8,4.6,1.5,"Versicolor" +5.7,2.8,4.5,1.3,"Versicolor" +6.3,3.3,4.7,1.6,"Versicolor" +4.9,2.4,3.3,1,"Versicolor" +6.6,2.9,4.6,1.3,"Versicolor" +5.2,2.7,3.9,1.4,"Versicolor" +5,2,3.5,1,"Versicolor" +5.9,3,4.2,1.5,"Versicolor" +6,2.2,4,1,"Versicolor" +6.1,2.9,4.7,1.4,"Versicolor" +5.6,2.9,3.6,1.3,"Versicolor" +6.7,3.1,4.4,1.4,"Versicolor" +5.6,3,4.5,1.5,"Versicolor" +5.8,2.7,4.1,1,"Versicolor" +6.2,2.2,4.5,1.5,"Versicolor" +5.6,2.5,3.9,1.1,"Versicolor" +5.9,3.2,4.8,1.8,"Versicolor" +6.1,2.8,4,1.3,"Versicolor" +6.3,2.5,4.9,1.5,"Versicolor" +6.1,2.8,4.7,1.2,"Versicolor" +6.4,2.9,4.3,1.3,"Versicolor" +6.6,3,4.4,1.4,"Versicolor" +6.8,2.8,4.8,1.4,"Versicolor" +6.7,3,5,1.7,"Versicolor" +6,2.9,4.5,1.5,"Versicolor" +5.7,2.6,3.5,1,"Versicolor" +5.5,2.4,3.8,1.1,"Versicolor" +5.5,2.4,3.7,1,"Versicolor" +5.8,2.7,3.9,1.2,"Versicolor" +6,2.7,5.1,1.6,"Versicolor" +5.4,3,4.5,1.5,"Versicolor" +6,3.4,4.5,1.6,"Versicolor" +6.7,3.1,4.7,1.5,"Versicolor" +6.3,2.3,4.4,1.3,"Versicolor" +5.6,3,4.1,1.3,"Versicolor" +5.5,2.5,4,1.3,"Versicolor" +5.5,2.6,4.4,1.2,"Versicolor" +6.1,3,4.6,1.4,"Versicolor" +5.8,2.6,4,1.2,"Versicolor" +5,2.3,3.3,1,"Versicolor" +5.6,2.7,4.2,1.3,"Versicolor" +5.7,3,4.2,1.2,"Versicolor" +5.7,2.9,4.2,1.3,"Versicolor" +6.2,2.9,4.3,1.3,"Versicolor" +5.1,2.5,3,1.1,"Versicolor" +5.7,2.8,4.1,1.3,"Versicolor" +6.3,3.3,6,2.5,"Virginica" +5.8,2.7,5.1,1.9,"Virginica" +7.1,3,5.9,2.1,"Virginica" +6.3,2.9,5.6,1.8,"Virginica" +6.5,3,5.8,2.2,"Virginica" +7.6,3,6.6,2.1,"Virginica" +4.9,2.5,4.5,1.7,"Virginica" +7.3,2.9,6.3,1.8,"Virginica" +6.7,2.5,5.8,1.8,"Virginica" +7.2,3.6,6.1,2.5,"Virginica" +6.5,3.2,5.1,2,"Virginica" +6.4,2.7,5.3,1.9,"Virginica" +6.8,3,5.5,2.1,"Virginica" +5.7,2.5,5,2,"Virginica" +5.8,2.8,5.1,2.4,"Virginica" +6.4,3.2,5.3,2.3,"Virginica" +6.5,3,5.5,1.8,"Virginica" +7.7,3.8,6.7,2.2,"Virginica" +7.7,2.6,6.9,2.3,"Virginica" +6,2.2,5,1.5,"Virginica" +6.9,3.2,5.7,2.3,"Virginica" +5.6,2.8,4.9,2,"Virginica" +7.7,2.8,6.7,2,"Virginica" +6.3,2.7,4.9,1.8,"Virginica" +6.7,3.3,5.7,2.1,"Virginica" +7.2,3.2,6,1.8,"Virginica" +6.2,2.8,4.8,1.8,"Virginica" +6.1,3,4.9,1.8,"Virginica" +6.4,2.8,5.6,2.1,"Virginica" +7.2,3,5.8,1.6,"Virginica" +7.4,2.8,6.1,1.9,"Virginica" +7.9,3.8,6.4,2,"Virginica" +6.4,2.8,5.6,2.2,"Virginica" +6.3,2.8,5.1,1.5,"Virginica" +6.1,2.6,5.6,1.4,"Virginica" +7.7,3,6.1,2.3,"Virginica" +6.3,3.4,5.6,2.4,"Virginica" +6.4,3.1,5.5,1.8,"Virginica" +6,3,4.8,1.8,"Virginica" +6.9,3.1,5.4,2.1,"Virginica" +6.7,3.1,5.6,2.4,"Virginica" +6.9,3.1,5.1,2.3,"Virginica" +5.8,2.7,5.1,1.9,"Virginica" +6.8,3.2,5.9,2.3,"Virginica" +6.7,3.3,5.7,2.5,"Virginica" +6.7,3,5.2,2.3,"Virginica" +6.3,2.5,5,1.9,"Virginica" +6.5,3,5.2,2,"Virginica" +6.2,3.4,5.4,2.3,"Virginica" +5.9,3,5.1,1.8,"Virginica" \ No newline at end of file diff --git a/Task/Sumanta Kumar Dutta/mango.jpg b/Task/Sumanta Kumar Dutta/mango.jpg new file mode 100644 index 0000000..fc6a5c3 Binary files /dev/null and b/Task/Sumanta Kumar Dutta/mango.jpg differ