Question
a Python program is typically run by calling the main() function which takes no parameters. The main() function calls the other functions required by the
a Python program is typically run by calling the main() function which takes no parameters. The main() function calls the other functions required by the program to perform its tasks. For this question, you will need to complete the main() function of a program that finds the middle index of a string, splits the string at this middle index, and creates a new string with the halves of the original string in reverse order. To achieve this, the main() function needs to call the following two functions:
- The get_middle_index() function takes a single string parameter word. It returns the middle index of this string.
- The reverse_halves_of_string() function takes a single string parameter word, and an integer value middle_index. The function splits word at this middle index and returns a new string with the halves of word in reverse order.
The get_middle_index() and reverse_halves_of_string() functions have been done for you and their code has been entered into the answer box - do not alter these functions in any way. You must complete the main() function that calls them. Your main() function should:
- Prompt the user to enter a word using the provided prompt.
- Call the get_middle_index() function to obtain the middle index of the word the user has entered.
- Call the reverse_halves_of_string() function to obtain a new word with the halves of the word entered by the user in reverse order.
- Print both the original word and the new word.
You can assume that the user will always ent
er a word with a length of at least 2. Some examples of the main() function are shown below.
For example:
Test | Input | Result |
---|---|---|
main() | computer | Please enter a word: computer Original word: computer New word: utercomp |
main() | world | Please enter a word: world Original word: world New word: rldwo |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started