diff --git a/Task/SarthakGupta/Q1.py b/Task/SarthakGupta/Q1.py new file mode 100644 index 0000000..e64cf6e --- /dev/null +++ b/Task/SarthakGupta/Q1.py @@ -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") \ No newline at end of file diff --git a/Task/SarthakGupta/Q10.py b/Task/SarthakGupta/Q10.py new file mode 100644 index 0000000..88d32c9 --- /dev/null +++ b/Task/SarthakGupta/Q10.py @@ -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) diff --git a/Task/SarthakGupta/Q2.py b/Task/SarthakGupta/Q2.py new file mode 100644 index 0000000..a5780ff --- /dev/null +++ b/Task/SarthakGupta/Q2.py @@ -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 + + + diff --git a/Task/SarthakGupta/Q3.py b/Task/SarthakGupta/Q3.py new file mode 100644 index 0000000..6a14c08 --- /dev/null +++ b/Task/SarthakGupta/Q3.py @@ -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) + + diff --git a/Task/SarthakGupta/Q4.py b/Task/SarthakGupta/Q4.py new file mode 100644 index 0000000..42eb980 --- /dev/null +++ b/Task/SarthakGupta/Q4.py @@ -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() diff --git a/Task/SarthakGupta/Q5.py b/Task/SarthakGupta/Q5.py new file mode 100644 index 0000000..bebf031 --- /dev/null +++ b/Task/SarthakGupta/Q5.py @@ -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() diff --git a/Task/SarthakGupta/Q6.py b/Task/SarthakGupta/Q6.py new file mode 100644 index 0000000..7563cbb --- /dev/null +++ b/Task/SarthakGupta/Q6.py @@ -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)}") + diff --git a/Task/SarthakGupta/Q7.py b/Task/SarthakGupta/Q7.py new file mode 100644 index 0000000..a70e891 --- /dev/null +++ b/Task/SarthakGupta/Q7.py @@ -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) diff --git a/Task/SarthakGupta/Q7text.txt b/Task/SarthakGupta/Q7text.txt new file mode 100644 index 0000000..d873a72 --- /dev/null +++ b/Task/SarthakGupta/Q7text.txt @@ -0,0 +1,3 @@ +2 +5 +10 \ No newline at end of file diff --git a/Task/SarthakGupta/Q8.py b/Task/SarthakGupta/Q8.py new file mode 100644 index 0000000..de0a290 --- /dev/null +++ b/Task/SarthakGupta/Q8.py @@ -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) diff --git a/Task/SarthakGupta/test1.txt b/Task/SarthakGupta/test1.txt new file mode 100644 index 0000000..3d3945a --- /dev/null +++ b/Task/SarthakGupta/test1.txt @@ -0,0 +1,2 @@ +5 +1 2 3 4 5 \ No newline at end of file