293,990 views
5 votes
5 votes
Create a recursive procedure named (accumulator oddsum next). The procedure will return the sum of the odd numbers entered from the keyboard. The procedure will read a sequence of numbers from the keyboard, where parameter oddsum will keep track of the sum from the odd numbers entered so far and parameter next will (read) the next number from the keyboard.

User Blackfizz
by
3.3k points

1 Answer

26 votes
26 votes

Answer:

Step-by-step explanation:

The following procedure is written in Python. It takes the next argument, checks if it is an odd number and if so it adds it to oddsum. Then it asks the user for a new number from the keyboard and calls the accumulator procedure/function again using that number. If any even number is passed the function terminates and returns the value of oddsum.

def accumulator(next, oddsum = 0):

if (next % 2) != 0:

oddsum += next

newNext = int(input("Enter new number: "))

return accumulator(newNext, oddsum)

else:

return oddsum

Create a recursive procedure named (accumulator oddsum next). The procedure will return-example-1
User Dawei
by
2.6k points