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 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..fd9ea29 100644 --- a/problems/easy/easy_q11.py +++ b/problems/easy/easy_q11.py @@ -9,10 +9,13 @@ def day_of_week(day): 6: "Saturday", 7: "Sunday" } - return switch[8] + return switch[day] if __name__ == "__main__": - - xcd = day_of_week(32) - print(xcd) + day=int(input("Enter the number : ")) + if 0 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_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 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 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 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