From f07bd88fd90e7c681bc95843808d5e75b3a1f3d5 Mon Sep 17 00:00:00 2001 From: Swarup Dash <161138214+SwarupD21@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:18:00 +0530 Subject: [PATCH 1/4] Create Q10.py --- Task/Swarup Dash/Q10.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Task/Swarup Dash/Q10.py diff --git a/Task/Swarup Dash/Q10.py b/Task/Swarup Dash/Q10.py new file mode 100644 index 0000000..52cb81a --- /dev/null +++ b/Task/Swarup Dash/Q10.py @@ -0,0 +1,31 @@ +R = int(input("Enter the number of rows:")) +C = int(input("Enter the number of columns:")) + +matrix = [] +print("Enter the entries rowwise:") + +for i in range(R): # A for loop for row entries + a =[] + for j in range(C): # A for loop for column entries + a.append(int(input())) + matrix.append(a) + + +for i in range(R): + for j in range(C): + print(matrix[i][j], end = " ") + print() + +transpose = [] +for j in range(C): + transpose.append([]) + for i in range (R): + t_num = matrix[i][j] + transpose[j].append(t_num) + +#printing the transpose matrix +print('Transpose matrix: ') +for i in range (R): + for j in range (C): + print (transpose[i][j], end = ' ') + print() From 87394205768e8d856fbdc7fd19f3c07ca966f711 Mon Sep 17 00:00:00 2001 From: Swarup Dash <161138214+SwarupD21@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:20:03 +0530 Subject: [PATCH 2/4] Delete Task/Swarup Dash directory --- Task/Swarup Dash/Q10.py | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 Task/Swarup Dash/Q10.py diff --git a/Task/Swarup Dash/Q10.py b/Task/Swarup Dash/Q10.py deleted file mode 100644 index 52cb81a..0000000 --- a/Task/Swarup Dash/Q10.py +++ /dev/null @@ -1,31 +0,0 @@ -R = int(input("Enter the number of rows:")) -C = int(input("Enter the number of columns:")) - -matrix = [] -print("Enter the entries rowwise:") - -for i in range(R): # A for loop for row entries - a =[] - for j in range(C): # A for loop for column entries - a.append(int(input())) - matrix.append(a) - - -for i in range(R): - for j in range(C): - print(matrix[i][j], end = " ") - print() - -transpose = [] -for j in range(C): - transpose.append([]) - for i in range (R): - t_num = matrix[i][j] - transpose[j].append(t_num) - -#printing the transpose matrix -print('Transpose matrix: ') -for i in range (R): - for j in range (C): - print (transpose[i][j], end = ' ') - print() From 54ed8f430bf556210c65c613ec3741923a5a358a Mon Sep 17 00:00:00 2001 From: Swarup Dash <161138214+SwarupD21@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:21:46 +0530 Subject: [PATCH 3/4] Create Q10.py --- Task/Swarup Dash/Q10.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Task/Swarup Dash/Q10.py diff --git a/Task/Swarup Dash/Q10.py b/Task/Swarup Dash/Q10.py new file mode 100644 index 0000000..52cb81a --- /dev/null +++ b/Task/Swarup Dash/Q10.py @@ -0,0 +1,31 @@ +R = int(input("Enter the number of rows:")) +C = int(input("Enter the number of columns:")) + +matrix = [] +print("Enter the entries rowwise:") + +for i in range(R): # A for loop for row entries + a =[] + for j in range(C): # A for loop for column entries + a.append(int(input())) + matrix.append(a) + + +for i in range(R): + for j in range(C): + print(matrix[i][j], end = " ") + print() + +transpose = [] +for j in range(C): + transpose.append([]) + for i in range (R): + t_num = matrix[i][j] + transpose[j].append(t_num) + +#printing the transpose matrix +print('Transpose matrix: ') +for i in range (R): + for j in range (C): + print (transpose[i][j], end = ' ') + print() From 2bcb24c8e692c1a565fbcdfc11275f33a513df57 Mon Sep 17 00:00:00 2001 From: Swarup Dash <161138214+SwarupD21@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:22:28 +0530 Subject: [PATCH 4/4] Add files via upload --- Task/Swarup Dash/Q1Anagram.py | 31 +++++++++++++++++++++++++++++++ Task/Swarup Dash/Q2_Frequency.py | 28 ++++++++++++++++++++++++++++ Task/Swarup Dash/Q6_Prime.py | 20 ++++++++++++++++++++ Task/Swarup Dash/Q8_Freqdict.py | 14 ++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 Task/Swarup Dash/Q1Anagram.py create mode 100644 Task/Swarup Dash/Q2_Frequency.py create mode 100644 Task/Swarup Dash/Q6_Prime.py create mode 100644 Task/Swarup Dash/Q8_Freqdict.py diff --git a/Task/Swarup Dash/Q1Anagram.py b/Task/Swarup Dash/Q1Anagram.py new file mode 100644 index 0000000..c24ce2c --- /dev/null +++ b/Task/Swarup Dash/Q1Anagram.py @@ -0,0 +1,31 @@ +def is_anagram(s, t): + + if len(s) != len(t): + return False + + count_s = [0] * 26 #list of size 26 to store each 26 alphabet :) + count_t = [0] * 26 #list of size 26 to store each 26 alphabet :) + + for char in s: + index = ord(char) - ord('a') #Ascii value of a=97 + count_s[index] += 1 + + for char in t: + index = ord(char) - ord('a') + count_t[index] += 1 + + for i in range(26): + if count_s[i] != count_t[i]: + return False + return True + +#Example 1 +s1 = "anagram" +t1 = "nagaram" +print(is_anagram(s1, t1)) + +#Example 2 +s2 = "rat" +t2 = "car" +print(is_anagram(s2, t2)) + diff --git a/Task/Swarup Dash/Q2_Frequency.py b/Task/Swarup Dash/Q2_Frequency.py new file mode 100644 index 0000000..467bf36 --- /dev/null +++ b/Task/Swarup Dash/Q2_Frequency.py @@ -0,0 +1,28 @@ +def char_frequency(s): + frequency = {} + + uppercase_letters = [] + lowercase_letters = [] + + for char in s: + if char in frequency: + frequency[char] += 1 + else: + frequency[char] = 1 + if char.isupper(): + uppercase_letters.append(char) + else: + lowercase_letters.append(char) + + all_letters = [chr(i) for i in range(ord('A'), ord('Z') + 1)] + \ + [chr(i) for i in range(ord('a'), ord('z') + 1)] + + + for char in all_letters: + if char in frequency: + print(f"{char}: {frequency[char]}") + + +#Example: +s = "Robotics Society" +char_frequency(s) diff --git a/Task/Swarup Dash/Q6_Prime.py b/Task/Swarup Dash/Q6_Prime.py new file mode 100644 index 0000000..076b7bc --- /dev/null +++ b/Task/Swarup Dash/Q6_Prime.py @@ -0,0 +1,20 @@ +lower = int(input ("Please, Enter the Lowest Range Value: ")) +upper= int(input ("Please, Enter the Upper Range Value: ")) + +lst=[] +print ("The Prime Numbers in the range are: ") +for number in range (lower, upper + 1): + if number > 1: + for i in range (2, number): + if (number % i) == 0: + break + else: + lst.append(number) + +print(lst) + +large_primeno=max(lst) +small_primeno=min(lst) + +absolute_diff=large_primeno-small_primeno +print("The absolute diff between largest and smallest prime number is:",absolute_diff) \ No newline at end of file diff --git a/Task/Swarup Dash/Q8_Freqdict.py b/Task/Swarup Dash/Q8_Freqdict.py new file mode 100644 index 0000000..bec19ae --- /dev/null +++ b/Task/Swarup Dash/Q8_Freqdict.py @@ -0,0 +1,14 @@ +def count_frequency(lst): + + frequency_dict = {} + for element in lst: + if element in frequency_dict: + frequency_dict[element] += 1 + else: + frequency_dict[element] = 1 + return frequency_dict + + +sample_list = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4,4] +frequency_dict = count_frequency(sample_list) +print(frequency_dict)