Question: Question 2 . 0 Write a function Sum ( n ) that takes a non - negative integer ( n ) and returns the sum

Question 2.0
Write a function Sum(n) that takes a non-negative integer (n) and returns the sum of its digits (digit_sum ) as an integer. If n is negative and/or non-integer, the
function should return "Invalid Input." Be careful with your string formatting. Minor differences will result in a failed test.
Test your Sum(n) function for n=200500 in the following cell. Assign the output to q02. Feel free to try it for other inputs.
Hint: Strings are iterable.
Examples:11245'Invalid Input.''Invalid Input.'a
6
Question 2 . 0 Write a function Sum ( n ) that

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 Programming Questions!