11. Input a string and determine
whether it is a palindrome or not; convert the case of characters in the string.
Python
string = input("Enter
a string: ")
#
Check for palindrome
string = string.lower() # Convert
to lowercase for case-insensitive comparison
if string == string[::-1]:
print(string, "is a palindrome")
else:
print(string, "is not a palindrome")
#
Convert case of characters
converted_string = ""
for char in string:
if char.isupper():
converted_string += char.lower()
else:
converted_string += char.upper()
print("Converted
string:",
converted_string)
No comments:
Post a Comment