Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Task/Sumanta Kumar Dutta/Q1.py
Original file line number Diff line number Diff line change
@@ -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")
51 changes: 51 additions & 0 deletions Task/Sumanta Kumar Dutta/Q10.py
Original file line number Diff line number Diff line change
@@ -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)
20 changes: 20 additions & 0 deletions Task/Sumanta Kumar Dutta/Q2.py
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions Task/Sumanta Kumar Dutta/Q3.py
Original file line number Diff line number Diff line change
@@ -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)
49 changes: 49 additions & 0 deletions Task/Sumanta Kumar Dutta/Q4.py
Original file line number Diff line number Diff line change
@@ -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()
13 changes: 13 additions & 0 deletions Task/Sumanta Kumar Dutta/Q5.py
Original file line number Diff line number Diff line change
@@ -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()
37 changes: 37 additions & 0 deletions Task/Sumanta Kumar Dutta/Q6.py
Original file line number Diff line number Diff line change
@@ -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)
35 changes: 35 additions & 0 deletions Task/Sumanta Kumar Dutta/Q7.py
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 16 additions & 0 deletions Task/Sumanta Kumar Dutta/Q8.py
Original file line number Diff line number Diff line change
@@ -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)
30 changes: 30 additions & 0 deletions Task/Sumanta Kumar Dutta/Q9.py
Original file line number Diff line number Diff line change
@@ -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())
Loading