Intro to Computer Science
PA04
Code due by Feb 19th at 11:00 AM
Introduction
The aim of this project is practice the use of while loops and conditionals statements within a project that is a little bit bigger than ones you have been working on. This will give you some practice with Program Development from chapter 3 in your textbook. Take the time to really think about this problem and work through the process before you begin to code. Write small snippets of code to make sure you can perform smaller pieces of the assignment rather than jumping in and writing the whole program at once.
Quick Overview
You are going to write a program that prompts the user for an
integer and then determines the additive persistence and corresponding additive
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
Additive
persistence (http://mathworld.wolfram.com/AdditivePersistence.html) is a property of the sum of the digits of an integer. The sum of the
digits is found, and then the summation of digits is performed on the sum,
repeating until a single integer digit is reached. The number of such cycles is
that integer’s additive persistence. Consider the following example:
1. The beginning integer is 1234
2. Sum 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 1. When the value reaches a single digit, we are finished.
This final integer is the additive 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 integer’s additive digital root. The additive
digital root of 1234 is 1.
Multiplicative Persistence
The multiplicative persistence (http://mathworld.wolfram.com/MultiplicativePersistence.html
)and resulting multiplicative root are determined the same way, only multiplying
the digits of an integer instead of adding. For example
1. The beginning integer is 1234
2. The product of 1*2*3*4 = 24
3. The integer is now 24
4. The product of 2*4 = 8
5. The integer is now 8. When the value reaches a single digit, we are finished.
This final integer is the multiplicative root.
As before, the number of cycles is the multiplicative persistence. For 1234, the
multiplicative persistence is 2, and its multiplicative root is 8.
Program Specification
In a file named persistence.py you should write a program that runs as follows:
Getting Started
Example during development:
Note that the cycles demonstrate the use of “diagnostic output” (see
(4) under “Getting Started”). Your final program should not print out such
diagnostic output.
Example of final deliverable:
Final Submission
To upload your homework for grading, log on to eLearning, select this class, and navigate to the "Assignment Submissions" area. Click on the "Programming Assignment 4" folder and upload the python file named persistence.py in its designated location.