# Use the Design Recipe to write a function called my_sum  that consumes one parameter, assumed to be a non-negative integer. Return the sum of all integers between 0 and this number, inclusive. Do not use the built-in sum function. Include a docstring!Write 3 assertEqual statements to test your function

Question
27 views
Use the Design Recipe to write a function called my_sum  that consumes one parameter, assumed to be a non-negative integer. Return the sum of all integers between 0 and this number, inclusive. Do not use the built-in sum function. Include a docstring!

Write 3 assertEqual statements to test your function

check_circle

Step 1

The python program obeys the following rubrics:

• Defining a function my_sum which accepts a parameter, assumed to be a non-negative integer.
• Declaring an integer variable sum whose values is equal to 0.
• Using a for loop in the my_sum function to calculate the sum of number.
• The range of for loop starts from 0 to num+1.
• Completing the function definition
• Now, displaying the message to user to enter the number.
• Calling my_sum function and displaying the sum.
• Use proper indentation to run the program successfully.
Step 2

Program code in python:

'defining function with name'

def my_sum(number):

'declaring of integer variable sum=0'

sum=0

'using for loop, range of given for loop is 0 to num+1'

for j in range(0,number+1):

'calculating the total sum of values'

sum=sum+j

&nb...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in