Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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