Question
Python3 ** It would be helpful if you could write the program in a way that is easy to understand ** Use of Recursion: Programming
Python3
** It would be helpful if you could write the program in a way that is easy to understand **
Use of Recursion:
Programming Problem 1:
(Sum the digits in an integer using recursion)
Write a recursive function that computes the sum of the digits in an integer. Use the following function header:
def sumDigits(n):
For example, sumDigits(234) returns 9. Write a test program that prompts the user to enter an integer and displays the sum of its digits.
Sample Run
Enter an integer: 231498
The sum of digits in 231498 is 27
Analysis:
# Describe the problem including input and output in your own words
Design:
# Describe the major steps (algorithm) for solving the problem
Code:
# Python3 program
Test:
#output
-----------------------------------
Programming Problem 2:
(Print the characters in a string reversely)
Write a recursive function that displays a string reversely on the console using the following header:
def reverseDisplay(value):
For example, reverseDisplay("abcd") displays dcba. Write a test program that prompts the user to enter a string and displays its reversal.
Sample Run
Enter a string: abcd
dcba
Analysis:
# Describe the problem including input and output in your own words
Design:
# Describe the major steps (algorithm) for solving the problem
Code:
# Python3 program
Test:
#output
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