# ask user for input
user_input = input("Enter a string: ")
def is_palindrome(input_str):
# takes the input and takes out any spaces and makes it lower case for case-sensitive
input_str = input_str.replace(" ", "").lower()
# compare the string with its reverse
return input_str == input_str[::-1]
# takes parameter, user_input which is the string the user put and the function is_palindrome takes it as an argument
if is_palindrome(user_input):
print("The input is a palindrome.")
else:
print("The input is not a palindrome.")
The input is a palindrome.
# sorting function to sort a list of names alphabetically
def sort_names(names):
sorted_names = sorted(names)
return sorted_names
# list of names
name_list = []
# loop to add user input of names to name_list
while True:
name = input("Enter a name (or 'done' to finish): ")
# if user types done. break the loop
if name.lower() == "done":
break
# add the user input name to name_list list
name_list.append(name)
# sort the list of names using the sorting function
sorted_names = sort_names(name_list)
# display the sorted list of names
print("Sorted names:")
for name in sorted_names:
print(name)
Sorted names:
Aidan
Daniel
Nathan
Rayyan
##