Question: Python 3.4 This is my code but I don't think it is a recursive function. How can I fix it to recursive function? def sum_odds(nums):

Python 3.4 This is my code but I don't think it isPython 3.4 This is my code but I don't think it is a recursive function. How can I fix it to recursive function?

def sum_odds(nums): sum = 0 for i in nums: if i % 2 != 0: if sum == len(nums): return sum else: sum += i return sum 

Some Advice on Writing Recursive Functions Many students find it helpful when writing recursive functions to first write the function using iteration (loops). Doing so helps them to figure out the basic algorithm for solving the problem that can be transformed into a recursive solution. However, your final solutions MUST NOT not be iterative. Use of loops for a function will result in 0 points for that function. Part I: Sum of Odd Integers (2 points0 Write a recursive function sum-odds that takes a non-empty list of integers as an argument and returns the sum of only the odd integers in the list. In class we explored a recursive function called rsum that recursively computes the sum of a list of integers use it as a model to get started. Your function must be recursive and must not use any loops. Examples: Function Call Return Value sum odds [1, 8, 5, 6, 3, 4, 9] 18 sum odds [5] sum odds (12, 6, 4, 8, -2, -20 j) 0

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