☆ Algorithms HW
problem 1
def is_palindrome(s):
s = s.replace(" ", "").lower()
return s == s[::-1]
user_input = input("Enter a string: ")
if is_palindrome(user_input):
print("Palindrome")
else:
print("Not a palindrome")
problem 2
def sort_numbers(input_file, output_file):
with open(input_file, 'r') as f:
numbers = [int(line.strip()) for line in f]
numbers.sort()
with open(output_file, 'w') as f:
for number in numbers:
f.write(f"{number}\n")
print(f"Numbers have been sorted and saved to '{output_file}'.")
input_file = "unsorted_numbers.txt"
output_file = "sorted_numbers.txt"
sort_numbers(input_file, output_file)