Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in python code please Task 3a: Summing Digits Write a function called sum.digits that takes a single argument, a positive integer up to five digits

image text in transcribed

image text in transcribed

in python code please

Task 3a: Summing Digits Write a function called sum.digits that takes a single argument, a positive integer up to five digits long (i.e., between 0 and 99999), and returns its sum. For example, for 5378 the sum is 5+3+7+8-23. Your output should look like the following sum digits (5378) 23 >>> 2 3 sum-digits (1) sum digits (11) sum digits (111) sum digits (11113) 10 Task 3b: If you sum the digits of a number and the result is a multiple of 3, then the original number is a multiple of 3. For large sums, you may have to think a bit before deciding whether a sum is a multiple of 3. To make life easier, you can sum the digits in the sum and see whether it results in a multiple of 3. You can continue to do this until it becomes obvious that the number is a multiple of 3-or not. Write a program that will prompt the user for an integer up to 5 digits long, sum the digits in this number, and display the results. It should then sum the digits in the sum and display the results. Your program should consist of a main function and the sum.digitsfunction. (Hint: Recall how you used divmod () to find the number of dollars, quarters, dimes, nickels, and pennies to make change in your last lab.) The output should be similar to the following 1 Enter an integer up to 5 digits long: 99999 2 Sum of digits in 99999: 45 Sum of digits in 45: 9 1Enter an integer up to 5 digits long: 1234 2 Sum of digits in 1234: 10 3 Sum of digits in 10:1 1 Enter an integer up to 5 digits long:75 2 Sum of digits in 75 12 Sum of digits in 12: 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What lessons in intervention design, does this case represent?

Answered: 1 week ago