16.8k views
5 votes
% Write a procedure that calculates the sum of the numbers in % a given range. The parameters to this procedure should be % as follows: % % 1. The low end of the range % 2. The high end of the range % 3. The sum of the values in the range % % If the low end equals the high end, then the sum should be % whatever value is equal to the low/high end (the range is % inclusive). If the low end is greater than the high end, % then failure should occur.

1 Answer

4 votes

Answer:

The procedure in python 3 is as follows:

def add_range(low,high):

if low<= high:

total = 0

for i in range(low,high+1):

total+=i

return total

else:

return "Failure"

Step-by-step explanation:

This defines the function/procedure

def add_range(low,high):

If low is less or equal to high

if low<= high:

Initialize total to 0

total = 0

Add up numbers in the range

for i in range(low,high+1):

total+=i

Return the total

return total

If low is greater, then return failure

else:

return "Failure"

User Paflow
by
3.3k points