Question

Must satisfy the following: Define a function named series. This function will accept two arguments, both...

Must satisfy the following:

Define a function named series. This function will accept two arguments, both integers, named base and span. The function will compute the sum of the integers, starting at the value of base and down to 0 (zero) that are span apart. In other words, if base is 19 and span is 3, series will compute the sum of 19 + 16 + 13 + 10 + 7 + 4 + 1.

The series function does not need to handle negative base and span values, and these should not be tested for.

The implementation of series must be recursive, and thus must satisfy the three requirements for a recursive function. 1. It must call itself. 2. It must have a stopping condition. 3. It must reduce the problem with each recursive call.

The file must successfully load into a running Python program as a module via the use of the import command.

Homework Answers

Answer #1

#content of sumseries.py
def series(m,n):
s=0
#base case, recursion will terminate when the valueof m will be lessthan or 0
if m <= 0:
return s

# Recursive case:
else: #compute the sum
s= s + m + series(m-n,n)
return s #return s

#content of main.py

import sumseries #import the sumseries module
#input base and span values
base = (int)(input("Enter the value of base"))
span = (int)(input("Enter the value of span"))
if(base<=0 or span<=0): #validate the inputs
print("Invalid Input")
else:
#call series() for sum of sumseries module
print("Sum of series is : ",sumseries.series(base,span))

output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • In C++ ------------------------------------------ All functions take no parameters as input and return nothing. Create a function...
    asked 10 minutes ago
  • Based on the increasing theft rate in Sunset Harbor, the Harbor is planning to upgrade its...
    asked 11 minutes ago
  • Design a program that allows the user to enter 5 names into a String array. Sort...
    asked 14 minutes ago
  • Directions: Pair off into groups of 3-4 students. Please read and respond to all the following...
    asked 33 minutes ago
  • a) What, exactly, is the “State Income Tax (SIT)? What are the various tax rates in...
    asked 34 minutes ago
  • Identify the correct combinational circuit in the following analogy. Due to road construction, four lanes may...
    asked 35 minutes ago
  • Educators sometimes need access to student’s medical information when it relates to their performance and safety...
    asked 43 minutes ago
  • Write Python expressions corresponding to the following statements: The sum of the first five positive integers...
    asked 50 minutes ago
  • Write a function that passes an array argument, getRandomNumbers, to get a pointer to an array...
    asked 1 hour ago
  • An automobile is traveling at v0 = 30 meters per second, when the driver applies the...
    asked 1 hour ago
  • T=15C, RH=70%, P= 99.6KPa. Calculate i) the saturated vapor pressure es, ii) vapor pressure e; iii)...
    asked 1 hour ago
  • Computer Science, Website Design, Enhanced Business Technology Write three paragraphs (4-7 sentences each) with three website...
    asked 1 hour ago