diff --git a/palindrome_checker.py b/palindrome_checker.py new file mode 100644 index 0000000..bd9639d --- /dev/null +++ b/palindrome_checker.py @@ -0,0 +1,12 @@ +def is_palindrome(s): + # Remove any spaces and convert to lowercase to ensure accurate comparison + s = s.replace(" ", "").lower() + # Check if the string is equal to its reverse + return s == s[::-1] + +# Test the function +string = input() +if is_palindrome(string): + print("It's a palindrome!") +else: + print("It's not a palindrome.") \ No newline at end of file diff --git a/perfect_number.py b/perfect_number.py new file mode 100644 index 0000000..e697765 --- /dev/null +++ b/perfect_number.py @@ -0,0 +1,14 @@ +def is_perfect_number(n): + if n < 1: + return False # Perfect numbers are positive integers + + divisors_sum = sum(i for i in range(1, n) if n % i == 0) + + return divisors_sum == n + +# Test the function +number = int(input("Enter number to check")) +if is_perfect_number(number): + print(f"{number} is a perfect number!") +else: + print(f"{number} is not a perfect number.") \ No newline at end of file