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
10 changes: 10 additions & 0 deletions Task/SarthakGupta/Q1.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
str1 = input("Enter a word ")
str2 = input("Enter another word ")

str1 = sorted(str1)
str2 = sorted(str2)

if(str1 == str2):
print("The given words are anagram")
else:
print("The given words are not anagram")
18 changes: 18 additions & 0 deletions Task/SarthakGupta/Q10.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import numpy as np

r = int (input("Enter the rows of array"))
c = int (input("Enter the columns of array"))
a = np.zeros((r,c),dtype = 'int')

aT = np.zeros((c,r),dtype = 'int')

for i in range(r):
for j in range(c):
a[i][j] = int (input(f"Enter the element for row {r} and column {c} = "))

for i in range(r):
for j in range(c):
aT[j][i] = a[i][j]


print(aT)
20 changes: 20 additions & 0 deletions Task/SarthakGupta/Q2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
st = input("Enter input ")
st = "".join(sorted(st))
l = len(st)
i = 0
count = 0

while i < l:
c = st[i]
if(c == 32):
i+=1
continue
count = 1
while i+1 < l and st[i+1] == c:
count += 1
i+=1
print(f"{c} ==> {count}")
i+=1



21 changes: 21 additions & 0 deletions Task/SarthakGupta/Q3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import numpy as np

a = input("Enter number")
l = len(a)
a = np.array(list(a),dtype = 'int32')

i = l-1

if(a[i]+1 == 10):
while(i>=0):
if(a[i]+1 >= 10):
a[i] = 0
a[i-1] += 1
i-=1
else:
a[i] += 1
i -= 1

print(a)


39 changes: 39 additions & 0 deletions Task/SarthakGupta/Q4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

import cv2
import numpy as np

# Open the webcam
cap = cv2.VideoCapture(0)

while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

lower_black = np.array([0, 0, 0])
upper_black = np.array([180, 255, 30])

lower_white = np.array([0, 0, 200])
upper_white = np.array([180, 30, 255])

mask_black = cv2.inRange(hsv, lower_black, upper_black)
mask_white = cv2.inRange(hsv, lower_white, upper_white)

contours_black, _ = cv2.findContours(mask_black, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

for cnt in contours_black:
x, y, w, h = cv2.boundingRect(cnt)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

contours_white, _ = cv2.findContours(mask_white, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

for cnt in contours_white:
x, y, w, h = cv2.boundingRect(cnt)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow('Webcam', frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()
15 changes: 15 additions & 0 deletions Task/SarthakGupta/Q5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import cv2 as cv
import numpy as np

cap = cv.VideoCapture(0);

while True:
_,frame = cap.read();
frame = cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
frame = cv.Canny(frame,80,150)
cv.imshow('WebCam',frame)
if cv.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv.destroyAllWindows()
31 changes: 31 additions & 0 deletions Task/SarthakGupta/Q6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import numpy as np
##You can make the changes in test1.txt to check the working of this program

def primeChecker(num):
if num <= 1:
return False

for i in range(2,int(num / 2)+1):
if num % i == 0:
return False
return True

f = open('test1.txt', 'r') # Passing Reference of file in read mode
N = int(f.readline()) # Reading the first line
arr = np.array(f.readline().split(),dtype = 'int32') # Reading the second line and converting it to a numpy array
print(N)
print(arr)
f.close()
minP = 2147483647 #Assigning the minP variable with max int value will facilitate store the min value
maxP = -2147483648 # Vice versa

for n in arr:
if primeChecker(n) :
if n > maxP :
maxP = n
if n < minP :
minP = n
print(minP)
print(maxP)
print(f"The abs diff of max and min prime number in this array is = {abs(maxP - minP)}")

27 changes: 27 additions & 0 deletions Task/SarthakGupta/Q7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def primeChecker(num):
if num <= 1:
return False
if num == 2:
return True
if num % 2 == 0:
return False
for i in range(3, int(num / 2) +1):
if num % i == 0:
return False
return True

f = open('Q7text.txt','r')
N = int (f.readline())
r = [0]*N# costs
rp = [0]*N #roys pay
for i in range(N):
r[i] = int (f.readline())
f.close()

for i in range(N):
for j in range(r[i]):
if primeChecker(j) :
if r[i] % j == 0:
rp[i] = r[i]-j
break
print(rp)
3 changes: 3 additions & 0 deletions Task/SarthakGupta/Q7text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2
5
10
11 changes: 11 additions & 0 deletions Task/SarthakGupta/Q8.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
str = input("Enter a string : ")
str = list(str)
ele_dict = {}
str.sort()
count = 0
for i in str:
if i in ele_dict:
ele_dict[i]+=1
else:
ele_dict[i] = 1
print(ele_dict)
2 changes: 2 additions & 0 deletions Task/SarthakGupta/test1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
5
1 2 3 4 5