diff --git a/FunProjects/arrayCompare.py b/FunProjects/arrayCompare.py index f6a38c4..08cb7c3 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])) 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 +lis1=eval(input("Enter list 1: ")) +lis2=eval(input("Enter list 2: ")) +print(comp(lis1,lis2)) \ No newline at end of file diff --git a/problems/easy/easy_q10.py b/problems/easy/easy_q10.py index 36e50ef..3ad440b 100644 --- a/problems/easy/easy_q10.py +++ b/problems/easy/easy_q10.py @@ -1,6 +1,14 @@ # Check Palindrome Number: Use a do-while loop to determine if a given number is a palindrome def is_palindrome(num): original = num + + reverse = 0 + while num != 0: + reverse = reverse * 10 + num % 10 + num //= 10 + + return reverse == original + reverse = '' while num != 0 : reverse += str(num % 10) @@ -9,6 +17,7 @@ def is_palindrome(num): return "It is a Palindrome" else: return "It is not a Palindrome" + if __name__ == "__main__": nums = int(input("Enter the Number: ")) res = is_palindrome(nums) diff --git a/problems/easy/easy_q11.py b/problems/easy/easy_q11.py index 3e01c4f..182540b 100644 --- a/problems/easy/easy_q11.py +++ b/problems/easy/easy_q11.py @@ -11,10 +11,19 @@ def day_of_week(day): } return switch[day] if __name__ == "__main__": + + day=int(input("Enter the number : ")) + if 0 b: + return a + else: + return b +if __name__ == "__main__": + num1 = int(input("Enter the First Number :")) + num2 = int(input("Enter the Second Number :")) + res = largest_of_two(num1,num2) + print(res) + print(num1,"larger") else: print(num2,"larger") @@ -31,3 +40,4 @@ def largest_of_two(a, b): main + diff --git a/problems/easy/easy_q3.py b/problems/easy/easy_q3.py index d52aa7b..2a6b7cc 100644 --- a/problems/easy/easy_q3.py +++ b/problems/easy/easy_q3.py @@ -9,9 +9,20 @@ def is_leap_year(year): return "Leap Year" if year % 4 == 0 and year % 100 != 0 or year % 400 == 0: + + + return "Leap Year" + return "Not a Leap Year" + + return " Leap Year" + else: + return "not a 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_q6.py b/problems/easy/easy_q6.py index 5e6ebd5..2a3d8c5 100644 --- a/problems/easy/easy_q6.py +++ b/problems/easy/easy_q6.py @@ -6,5 +6,10 @@ def print_numbers(n): i += 1 if __name__ == "__main__": + num = int(input("Enter the Number ")) + print_numbers(num) + + num = int(input("Enter the Number :")) print_numbers(num) + diff --git a/problems/easy/easy_q7.py b/problems/easy/easy_q7.py index 794c6a6..0b3053c 100644 --- a/problems/easy/easy_q7.py +++ b/problems/easy/easy_q7.py @@ -3,10 +3,18 @@ def sum_of_digits(num): total = 0 while num > 0: total += num % 10 + + num = num // 10 + 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_q9.py b/problems/easy/easy_q9.py index 43fc763..df9a503 100644 --- a/problems/easy/easy_q9.py +++ b/problems/easy/easy_q9.py @@ -8,6 +8,9 @@ def factorial(n): if __name__ == "__main__": num = int(input("Enter the Number :")) - res=factorial(num) - print(res) + + print(factorial(num)) + res=factorial(num) + print(res) + diff --git a/problems/medium/m1.py b/problems/medium/m1.py index ecb1be8..e5d9805 100644 --- a/problems/medium/m1.py +++ b/problems/medium/m1.py @@ -5,6 +5,16 @@ def math_operations_menu(choice): a, b = map(int, input("Enter two numbers(separated by commas): ").split(sep=",")) + + if choice == 2: + print("Subtraction:", a - b) + elif choice == 1: + print("Addition:", a + b) + elif choice == 4: + print("Division:", a / b) + elif choice == 3: + print("Multiplication:", a * b) + if choice == 1: print(f"Subtraction of {a} and {b}:{a - b}") elif choice == 2: @@ -13,11 +23,14 @@ def math_operations_menu(choice): print(f"Division of {a} and {b}:{a / b}") elif choice == 4: print(f"Multiplication of {a} and {b}:{a * b}") - elif choice == 5: + elif choice == 5: print(f"Modulus of {a} and {b}:{a // b}") elif choice == 6: print(f"{a} to the power of {b}:{a**b}") else: + print("Invalid option") +math_operations_menu() + print("Invalid option!!!") print("-------------Mathematical operation menu---------------") print("1. Add") @@ -28,4 +41,5 @@ def math_operations_menu(choice): print("6. Expontential") choice = int(input("Enter your choice: ")) math_operations_menu(choice) -print("-------------------------------------------------------") \ No newline at end of file +print("-------------------------------------------------------") + \ No newline at end of file diff --git a/problems/medium/m2.py b/problems/medium/m2.py index 3829f69..2b42991 100644 --- a/problems/medium/m2.py +++ b/problems/medium/m2.py @@ -15,8 +15,15 @@ def array_operations_menu(): print("Smallest Element:", min(arr)) elif choice == 4: arr.sort() + + print("Sorted Array:", arr) + else: + print("Invalid option") +array_operations_menu() + print("Sorted Array:",arr) else: print("Invalid option") array_operations_menu() + 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 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