Поставьте программу,которая меняет местами n-ю и m-ю буквы слова.

9 Фев 2020 в 19:53
165 +1
0
Ответы
1

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.

18 Апр 2024 в 17:39
Не можешь разобраться в этой теме?
Обратись за помощью к экспертам
Гарантированные бесплатные доработки в течение 1 года
Быстрое выполнение от 2 часов
Проверка работы на плагиат
Поможем написать учебную работу
Прямой эфир