Question: If an integer is divisible by 9 , then the sum of its digits produces a number that is also divisible by 9 . The

 If an integer is divisible by 9 , then the sum

If an integer is divisible by 9 , then the sum of its digits produces a number that is also divisible by 9 . The same is true for integers divisible by 3 . (a) Write a function called add that sums the digits of an integer. For example, summing the digits of the integer 3820488 gives 33. Hint: One way to do this is to use the str function. (b) Using a while loop, write another function that recursively calls add until you get a number that is 9 or smaller. Use this result to print out one of three outputs depending on which is true: - number is divisible by 3 and 9 - number is divisible by 3 but not by 9 - number is not divisible by 3 or 9 (c) Typically, how many calls to add are needed for the routine you wrote in part (b)? for a number with 5 digits? 10 digits? 30 digits? (Recall that Avogadro's number is 6.0221023 particles/mole so you are unlikely to run into meaningful integers too much longer than 30 digits.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!