# Untitled

unknown
plain_text
2 months ago
1.2 kB
5
Indexable
Never
```[0:24 pm, 28/02/2024] MANASH Amity: def is_palindrome(s):
# Convert the string to lowercase and remove non-alphanumeric characters
s = ''.join(char.lower() for char in s if char.isalnum())
# Check if the string is equal to its reverse
return s == s[::-1]

# Example usage:
print(is_palindrome("A man, a plan, a canal, Panama"))  # Output: True
print(is_palindrome("racecar"))  # Output: True
print(is_palindrome("hello"))  # Output: False
[0:24 pm, 28/02/2024] MANASH Amity: def is_power_of_b(a, b):
if a == 0:
return False
while a % b == 0:
a /= b
return a == 1

# Example usage:
print(is_power_of_b(16, 2))  # Output: True
print(is_power_of_b(27, 3))  # Output: True
print(is_power_of_b(10, 2))  # Output: False
[0:24 pm, 28/02/2024] MANASH Amity: def calculate_length_and_print(string):
length = 0
for char in string:
length += 1

print(f"{length:>{length}} {string}")

# Example usage:
calculate_length_and_print("Hello")
[0:24 pm, 28/02/2024] MANASH Amity: def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)

# Example usage:
number = 5
print(f"The factorial of {number} is {factorial(number)}")```