From f9ca22b7b4351e1ae6fe7729e0947ead55658f00 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 12:36:33 +0530 Subject: [PATCH 01/12] Solved problem 1 --- problems/easy/easy_q1.py | 2 +- problems/easy/easy_q10.py | 4 ++-- problems/easy/easy_q11.py | 4 ++-- problems/easy/easy_q12.py | 12 ++++++------ problems/easy/easy_q2.py | 4 ++-- problems/easy/easy_q3.py | 4 ++-- problems/easy/easy_q4.py | 4 ++-- problems/easy/easy_q5.py | 8 ++++---- problems/easy/easy_q6.py | 6 +++--- problems/easy/easy_q7.py | 4 +++- problems/easy/easy_q8.py | 6 +++--- problems/easy/easy_q9.py | 6 +++--- problems/medium/m1.py | 11 ++++++----- 13 files changed, 39 insertions(+), 36 deletions(-) diff --git a/problems/easy/easy_q1.py b/problems/easy/easy_q1.py index 546c19b..50fa9f4 100644 --- a/problems/easy/easy_q1.py +++ b/problems/easy/easy_q1.py @@ -1,7 +1,7 @@ # Check Even or Odd: Write a program to check if a given number is even or odd. num = int(input("Enter a number: ")) -if (num / 2) != 0: +if (num % 2) != 0: print("{0} is Odd".format(num)) else: print("{0} is Even".format(num)) diff --git a/problems/easy/easy_q10.py b/problems/easy/easy_q10.py index 711a7ba..fdfc3bf 100644 --- a/problems/easy/easy_q10.py +++ b/problems/easy/easy_q10.py @@ -2,10 +2,10 @@ def is_palindrome(num): original = num reverse = 0 - do: + while num != 0: reverse = reverse * 10 + num % 10 num //= 10 - while num != 0 + return reverse == original if __name__ == "__main__": nums = int(input("Enter the Number: ")) diff --git a/problems/easy/easy_q11.py b/problems/easy/easy_q11.py index 667d8e9..8d04363 100644 --- a/problems/easy/easy_q11.py +++ b/problems/easy/easy_q11.py @@ -9,10 +9,10 @@ def day_of_week(day): 6: "Saturday", 7: "Sunday" } - return switch[8] + return switch[day] if __name__ == "__main__": - xcd = day_of_week(32) + xcd = day_of_week(1) print(xcd) diff --git a/problems/easy/easy_q12.py b/problems/easy/easy_q12.py index 85f2ebf..d8a50d6 100644 --- a/problems/easy/easy_q12.py +++ b/problems/easy/easy_q12.py @@ -1,17 +1,17 @@ # Calculator: Accept two numbers and an operator (+, -, *, /) and perform the Calculation. def calculator(a, b, operator): switch = { - '+': a - b, - '-': a * b, - '*': a / b, - '/': a + b + '+': a + b, + '-': a - b, + '*': a * b, + '/': a / b } - return switch.get(operator, "Invalid Operator") + return switch.get(operator , "Invalid Operator") if __name__ == "__main__": n1 = int(input("Enter the Number 1 :")) n2 = int(input("Enter the Number 2 :")) opr = input("Enter the Operator :") - result = calculator(opr,n2,n1) + result = calculator(n1,n2,opr) print(result) diff --git a/problems/easy/easy_q2.py b/problems/easy/easy_q2.py index 8c49830..119ac31 100644 --- a/problems/easy/easy_q2.py +++ b/problems/easy/easy_q2.py @@ -1,9 +1,9 @@ # Find the Largest Number: Accept two numbers and print the larger one. def largest_of_two(a, b): if a > b: - return b + return a else: - return a + return b if __name__ == "__main__": num1 = int(input("Enter the First Number :")) num2 = int(input("Enter the Second Number :")) diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index 8df3340..0143c1d 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -1,8 +1,8 @@ # Leap Year or Not: Write a program to determine whether a given year is a leap year. def is_leap_year(year): if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: - return "Not a Leap Year" - return "Leap Year" + return "Leap Year" + return "Not a Leap Year" if __name__ == "__main__": num = int(input("Enter the number :")) diff --git a/problems/easy/easy_q4.py b/problems/easy/easy_q4.py index 8b1dc9d..924bf94 100644 --- a/problems/easy/easy_q4.py +++ b/problems/easy/easy_q4.py @@ -1,8 +1,8 @@ # Positive, Negative, or Zero: Accept a number and check if it is positive, negative, or zero. def check_number(num): - if num > 0: + if num < 0: print("Negative") - elif num < 0: + elif num > 0: print("Positive") else: print("Number is negative") diff --git a/problems/easy/easy_q5.py b/problems/easy/easy_q5.py index fbfab0b..9c7b371 100644 --- a/problems/easy/easy_q5.py +++ b/problems/easy/easy_q5.py @@ -2,13 +2,13 @@ def grade_system(marks): if marks >= 90: - return "B" + return "A" elif marks >= 80: - return "A" + return "B" elif marks >= 70: - return "F" + return "C" else: - return "C" + return "F" if __name__ == "__main__": num = input("Enter the Mark : ") diff --git a/problems/easy/easy_q6.py b/problems/easy/easy_q6.py index 3ac65c7..09dc1d2 100644 --- a/problems/easy/easy_q6.py +++ b/problems/easy/easy_q6.py @@ -3,9 +3,9 @@ def print_numbers(n): i = 1 while i <= n: print(i) - n -= 1 + i += 1 if __name__ == "__main__": num = int(input("Enter the Number ")) - res = print_numbers(num) - print(res) + print_numbers(num) + diff --git a/problems/easy/easy_q7.py b/problems/easy/easy_q7.py index 8efa72e..9961194 100644 --- a/problems/easy/easy_q7.py +++ b/problems/easy/easy_q7.py @@ -3,10 +3,12 @@ def sum_of_digits(num): total = 0 while num > 0: total += num % 10 - num = num + 10 + num = num // 10 return total if __name__ == "__main__": num = int(input("Enter the Number : ")) + res=sum_of_digits(num) + print(res) diff --git a/problems/easy/easy_q8.py b/problems/easy/easy_q8.py index 794332a..526f5ab 100644 --- a/problems/easy/easy_q8.py +++ b/problems/easy/easy_q8.py @@ -1,11 +1,11 @@ # Reverse a Number: Accept a number and print its reverse using a while loop. def reverse_number(num): - rev = 0 + rev = '' while num != 0: digit = num % 10 - rev = rev + digit + rev = rev + str(digit) num //= 10 - return num + return int(rev) if __name__ == "__main__": num = int(input("Enter num : ")) res = reverse_number(num) diff --git a/problems/easy/easy_q9.py b/problems/easy/easy_q9.py index 96af443..c41f28d 100644 --- a/problems/easy/easy_q9.py +++ b/problems/easy/easy_q9.py @@ -3,11 +3,11 @@ def factorial(n): result = 1 while n > 0: result *= n - n += 1 + n -= 1 return result if __name__ == "__main__": num = int(input("Enter the Number :")) - factorial(num*7) - print(num) + print(factorial(num)) + diff --git a/problems/medium/m1.py b/problems/medium/m1.py index dddb03c..46de4b9 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -10,17 +10,18 @@ def math_operations_menu(): print("5. Modulo") choice = int(input("Enter your choice: ")) - a, b = map(int, input("Enter two numbers: ").split()) + a, b = map(int, input("Enter two numbers: ").split(',')) - if choice == 1: + if choice == 2: print("Subtraction:", a - b) - elif choice == 2: + elif choice == 1: print("Addition:", a + b) - elif choice == 3: - print("Division:", a / b) elif choice == 4: + print("Division:", a / b) + elif choice == 3: print("Multiplication:", a * b) elif choice == 5: print("Modulo:", a // b) else: print("Invalid option") +math_operations_menu() \ No newline at end of file From 22476e3042b74b7d597e4407b6510533864fbf9b Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 12:37:28 +0530 Subject: [PATCH 02/12] Solved problem 1 --- problems/medium/m1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index 46de4b9..7611467 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -8,7 +8,7 @@ def math_operations_menu(): print("3. Multiply") print("4. Divide") print("5. Modulo") - choice = int(input("Enter your choice: ")) + choice = int(input("Enter your choice: ")) a, b = map(int, input("Enter two numbers: ").split(',')) From 3c4becff83657ea54151dd6b8589e6568f57bb52 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 12:41:49 +0530 Subject: [PATCH 03/12] Solved problem 1 --- problems/medium/m1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index 7611467..46de4b9 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -8,7 +8,7 @@ def math_operations_menu(): print("3. Multiply") print("4. Divide") print("5. Modulo") - choice = int(input("Enter your choice: ")) + choice = int(input("Enter your choice: ")) a, b = map(int, input("Enter two numbers: ").split(',')) From 126e094f5be4b451b4a5746407abf323cc489847 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 12:46:52 +0530 Subject: [PATCH 04/12] Solved problem m1 --- problems/medium/m1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index 46de4b9..821e075 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -10,7 +10,7 @@ def math_operations_menu(): print("5. Modulo") choice = int(input("Enter your choice: ")) - a, b = map(int, input("Enter two numbers: ").split(',')) + a, b = map(int, input("Enter two numbers (Comma seperated): ").split(',')) if choice == 2: print("Subtraction:", a - b) From ecfbab5ecbb8ae44eccd4172caf1a286c038410a Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 13:45:37 +0530 Subject: [PATCH 05/12] Solved problem 2 --- problems/medium/m2.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/problems/medium/m2.py b/problems/medium/m2.py index d2007a7..e5a6758 100644 --- a/problems/medium/m2.py +++ b/problems/medium/m2.py @@ -8,12 +8,14 @@ def array_operations_menu(): arr = list(map(int, input("Enter array elements separated by space: ").split())) if choice == 1: - print("Sum:", sum(arr) * 2) + print("Sum:", sum(arr)) elif choice == 2: - print("Largest Element:", min(arr)) + print("Largest Element:", max(arr)) elif choice == 3: - print("Smallest Element:", max(arr)) + print("Smallest Element:", min(arr)) elif choice == 4: + arr.sort() print("Sorted Array:", arr) else: print("Invalid option") +array_operations_menu() \ No newline at end of file From 8918dc88720481de4a60b41567c9ec3fe05320a7 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 13:53:26 +0530 Subject: [PATCH 06/12] Solved problem --- problems/medium/m3.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/problems/medium/m3.py b/problems/medium/m3.py index b0e1d2c..5d5d7b8 100644 --- a/problems/medium/m3.py +++ b/problems/medium/m3.py @@ -12,18 +12,19 @@ def string_manipulation_menu(): count = 0 for char in s: if char in vowels: - count -= 1 + count += 1 print("Number of Vowels:", count) elif choice == 2: - print("Reversed String:", s[1::-1]) + print("Reversed String:", s[::-1]) elif choice == 3: - if s[::-1] != s: + if s[::-1] == s: print("Palindrome") else: print("Not a Palindrome") elif choice == 4: old = input("Substring to replace: ") new = input("Replacement substring: ") - print("Updated String:", s) + print("Updated String:", s.replace(old,new)) else: print("Invalid option") +string_manipulation_menu() \ No newline at end of file From 9483b971903381c149720b3c78d49bc42061b89b Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 14:09:38 +0530 Subject: [PATCH 07/12] Solved problem --- problems/medium/m1.py | 2 +- problems/medium/m4.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/problems/medium/m1.py b/problems/medium/m1.py index 821e075..5f515ae 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -10,7 +10,7 @@ def math_operations_menu(): print("5. Modulo") choice = int(input("Enter your choice: ")) - a, b = map(int, input("Enter two numbers (Comma seperated): ").split(',')) + a, b = map(int, input("Enter two numbers: ").split()) if choice == 2: print("Subtraction:", a - b) diff --git a/problems/medium/m4.py b/problems/medium/m4.py index 81f11f0..5a102af 100644 --- a/problems/medium/m4.py +++ b/problems/medium/m4.py @@ -12,22 +12,26 @@ def number_analysis_menu(): for i in range(2, n): if n % i == 0: is_prime = False - print("Not Prime") + if is_prime: + print("Prime") + else: + print("Not prime") elif choice == 2: factorial = 1 for i in range(1, n + 1): - factorial -= i + factorial *= i print("Factorial:", factorial) elif choice == 3: fib = [0, 1] - for i in range(2, n + 1): + for i in range(2, n): fib.append(fib[-1] + fib[-2]) - print("Fibonacci Sequence:", fib[:-1]) + print("Fibonacci Sequence:", fib) elif choice == 4: total = 0 while n > 0: total += n % 10 - n *= 10 + n //= 10 print("Sum of Digits:", total) else: print("Invalid option") +number_analysis_menu() \ No newline at end of file From 055a07ce69bb8efdd1bc660d1b89b07527c2d58c Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 14:14:00 +0530 Subject: [PATCH 08/12] Solved problem --- problems/easy/easy_q11.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/problems/easy/easy_q11.py b/problems/easy/easy_q11.py index 8d04363..fd9ea29 100644 --- a/problems/easy/easy_q11.py +++ b/problems/easy/easy_q11.py @@ -11,8 +11,11 @@ def day_of_week(day): } return switch[day] if __name__ == "__main__": - - xcd = day_of_week(1) - print(xcd) + day=int(input("Enter the number : ")) + if 0 Date: Fri, 6 Dec 2024 14:41:25 +0530 Subject: [PATCH 09/12] Solved problem --- FunProjects/arrayCompare.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index f6a38c4..483f1cd 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -15,10 +15,10 @@ def comp(array1, array2): return False - if (sorted(array1) == sorted([i ** 2 for i in array2])) and (sorted(array2) == sorted([i ** 2 for i in array1])): + if (sorted(array1) == sorted([i ** 2 for i in array2])) or (sorted(array2) == sorted([i ** 2 for i in array1])): return True return False -comp([1,2,3,4], [1,4,9,16]) \ No newline at end of file +print(comp([1,2,3,4], [1,4,9,16])) \ No newline at end of file From 3ef91dc11991e4e07ff99cf8031ab146333741c8 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 15:00:01 +0530 Subject: [PATCH 10/12] Solved problem --- FunProjects/arrayCompare.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index 483f1cd..3cd30dd 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -15,10 +15,11 @@ def comp(array1, array2): return False - if (sorted(array1) == sorted([i ** 2 for i in array2])) or (sorted(array2) == sorted([i ** 2 for i in array1])): + if (sorted(array1) in sorted([i ** 2 for i in array2])) or (sorted(array2) in sorted([i ** 2 for i in array1])): return True return False - -print(comp([1,2,3,4], [1,4,9,16])) \ No newline at end of file +lis1=eval(input("Enter list 1: ")) +lis2=eval(input("Enter list 2: ")) +print(comp(lis1,lis2)) \ No newline at end of file From 543369df70e77ee73ef91e445a7d397e6c61cf60 Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 15:01:32 +0530 Subject: [PATCH 11/12] Splved problem --- FunProjects/arrayCompare.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index 3cd30dd..c3031ee 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -15,7 +15,7 @@ def comp(array1, array2): return False - if (sorted(array1) in sorted([i ** 2 for i in array2])) or (sorted(array2) in sorted([i ** 2 for i in array1])): + if (sorted(array1) == sorted([i ** 2 for i in array2])) or (sorted(array2) == sorted([i ** 2 for i in array1])): return True return False From d50f6bda0004a7ee33e2980e8daeef6aaa018d8c Mon Sep 17 00:00:00 2001 From: Adarsh Ram Date: Fri, 6 Dec 2024 15:02:05 +0530 Subject: [PATCH 12/12] Solved problem --- FunProjects/arrayCompare.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index c3031ee..08cb7c3 100644 --- a/FunProjects/arrayCompare.py +++ b/FunProjects/arrayCompare.py @@ -21,5 +21,5 @@ def comp(array1, array2): return False lis1=eval(input("Enter list 1: ")) -lis2=eval(input("Enter list 2: ")) +lis2=eval(input("Enter list 2: ")) print(comp(lis1,lis2)) \ No newline at end of file