Question: You are going to write a program in Python 3.6 that prompts the user for an integer and then determines the additive persistence and corresponding
You are going to write a program in Python 3.6 that prompts the user for an integer and then determines the additive persistence and corresponding additive digital root, and the multiplicative persistence, the corresponding multiplicative digital root of that integer. You will continue to do so until the user quits.
Additive Persistence
1. The beginning integer is 1234
2. The sum of its digits is 1+2+3+4 = 10
3. The integer is now 10
4. The sum of its digits is 1 + 0 = 1
5. The integer is now 1. When the value reaches a single digit, we are done. This final integer is the additive digital root.
The number of cycles is the additive persistence. The integer 1234 has an additive persistence of 2 (first sum was 10, then the second sum was 1). The final digit reached is called the integers additive digital root. The additive digital root of 1234 is 1.
The multiplicative persistence and resulting multiplicative root are determined the same way, only multiplying the digits of an integer instead of adding.
Program Specification
1. Ask the user for an integer.
2. If the integer is less than 0, that is a signal to quit the program.
3. If the given integer is a single digit, report it's additive persistence and multiplicative persistence as 0 and both its additive and multiplicative root as itself.
4. If the given integer is more than a single digit, find the additive/multiplicative persistence and additive/miltiplicative root of the given integer and report the results to the user.
5. If the value was non-negative continue by prompting the user until they quit.
6. Get the whole thing to work with one or the other (additive, multiplicative) before you address the other.
7. How do you get the digits of an integer? Look at a combination of integer division (//) and modulo (%) operators on integers. Try it out first. You must not convert your integer to strings to extract the digits.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
