Sure, here is a simple program in Python that swaps the n-th and m-th characters of a word:
def swap_letters(word, n, m): if n < 0 or m < 0 or n >= len(word) or m >= len(word): return "Invalid indices" word_list = list(word) word_list[n], word_list[m] = word_list[m], word_list[n] swapped_word = "".join(word_list) return swapped_word word = input("Enter a word: ") n = int(input("Enter the index of the first letter to swap: ")) m = int(input("Enter the index of the second letter to swap: ")) result = swap_letters(word, n, m) print("Swapped word:", result)
You can run this program in any Python environment and enter a word along with the indices of the letters you want to swap. It will then output the word with the specified letters swapped.
Sure, here is a simple program in Python that swaps the n-th and m-th characters of a word:
def swap_letters(word, n, m):if n < 0 or m < 0 or n >= len(word) or m >= len(word):
return "Invalid indices"
word_list = list(word)
word_list[n], word_list[m] = word_list[m], word_list[n]
swapped_word = "".join(word_list)
return swapped_word
word = input("Enter a word: ")
n = int(input("Enter the index of the first letter to swap: "))
m = int(input("Enter the index of the second letter to swap: "))
result = swap_letters(word, n, m)
print("Swapped word:", result)
You can run this program in any Python environment and enter a word along with the indices of the letters you want to swap. It will then output the word with the specified letters swapped.