Question: Write a program (a4.py) that has 3 function definitions: count_iterative(), count_recursive(), and main(). Submit your a4.py on Canvas. You will write the code for the
Write a program (a4.py) that has 3 function definitions: count_iterative(), count_recursive(), and main(). Submit your a4.py on Canvas.
- You will write the code for the above functions.
- Both count functions (count_iterative() and count_recursive()) will compute the length of a string.
- The function count_iterative() must compute the length by using a loop to traverse the string.
- The function count_recursive() must compute the length without using a loop. It must call itself (use recursion).
- Both functions receive a string as a parameter and return an integer (the length of the string).
- You may not use the len() function while computing the length of the string. You must rely on the functions you are writing.
- You may not use any built-in python function or method, except for print() and input().
- The function main() must prompt the user to enter any string, then call both count functions (passing the same string as a parameter), and print the length of that string twice (the results from both function calls).
- At the bottom of a4.py (after the three function definitions), call main() to execute the code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
