Luffy wants to organize a surprise party for his friend Zoro and he wants to send a message to his friends, but he wants to encrypt the message so that Zoro cannot easily read it. The message is encrypted by exchanging pairs of characters. Description: This function gets a text (string) and creates a new text by swapping each pair of characters, and returns a string with the modified text. For example, suppose the text has 6 characters, then it swaps the first with the second, the third with the fourth and the fifth with the sixth character. Parameters: text is a string (its length could be 0) Return value: A string that is generated by swapping pairs of characters. Note that if the Examples: swap_text ("hello") s
Backstory:
Luffy wants to organize a surprise party for his friend Zoro and he wants to send a message to his friends, but he wants to encrypt the message so that Zoro cannot easily read it. The message is encrypted by exchanging pairs of characters.
Description: This function gets a text (string) and creates a new text by swapping each pair of characters, and returns a string with the modified text. For example, suppose the text has 6 characters, then it swaps the first with the second, the third with the fourth and the fifth with the sixth character.
Parameters: text is a string (its length could be 0)
Return value: A string that is generated by swapping pairs of characters. Note that if the
Examples:
swap_text ("hello") swap_text ("Party for Zoro!") swap_text ("") def which_day(numbers):→ 'ehllo'
→ 'aPtr yof roZor!' → ''
length of the text is odd, the last character remains in the same position.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images