in python
Part I: Sum of Odd Integers
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
1. sumOfOddInteger.py
def sumOfOddInteger(myList,size):
if size > 0:
if myList[size-1]%2!=0:
return myList[size-1]+sumOfOddInteger(myList,size-1)
else:
return sumOfOddInteger(myList,size-1)
else:
return 0
myList=[1,2,3,4];
print myList
print sumOfOddInteger(myList,4);
myList=[1,2,3,4,5,6,7,8,9]
print myList
print sumOfOddInteger(myList,9)
Steps to run & sample output is shown in below screenshot.
Write a recursive function sum-odds that takes a non-empty list of integers
****python**** Q1. Write a recursive function that returns the sum of all numbers up to and including the given value. This function has to be recursive; you may not use loops! For example: Test Result print('%d : %d' % (5, sum_up_to(5))) 5 : 15 Q2, Write a recursive function that counts the number of odd integers in a given list. This function has to be recursive; you may not use loops! For example: Test Result print('%s : %d' % ([2,...
Write a function maxList that takes in a list of integers as argument and returns their highest. You may not use the max() or the sorted() Python built-in functions.
Describe a non-recursive algorithm that takes a list of distinct integers a_1, a_2, ...., a_n and finds the sum of the primes in the list. Write your answer in pseudo-code or any well-known procedural language like Python, Java, C++, ..... You do not need to write a function to determine whether a number is prime. Assume it is part of your language. E.g. For the list 2, 3, 4, 5, 6, 7, your program should return 17 (because 2 +...
please explain each line of code! ( in python ) 1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Your function should take one parameter, root node. You may assume that the tree only contains integers. You may not call any methods from the LinkedBinaryTree class. Specifically, you should traverse the tree in your function def binary tree even sum (root): Returns the sum of al1 even integers in the binary tree 2....
Write a python program (recursive.py) that contains a main() function. The main() should test the following functions by calling each one with several different values. Here are the functions: 1) rprint - Recursive Printing: Design a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. 2) rmult - Recursive Multiplication: Design a recursive function that accepts two arguments into the parameters x and y. The function should return the value of x times...
Python 3.7 Question Recursively Converting a List of Digits to a Number Write a recursive function base2dec(digits, base) that takes the list of digits in the given base and returns the corresponding base 10 number.
need help with python ( no loops used please!) Write a recursive function named sum_digits that takes a given a non-negative integer N and returns the sum of its digits. Hint: Mod (%) by 10 gives you the rightmost digit (126 % 10 is 6), while doing integer division by 10 removes the rightmost digit (126/10 is 12). This function has to be recursive; you are not allowed to use loops to solve this problem! This function takes in one...
Use the FDR to design and write a function, maxValTimes, that takes a list of integers and returns a set containing the value(s) that occur the same number of times as the maximum value in the list. If the list is empty, return an empty set. For example if the list was [2,1,1,2,3,3,1] the function would return {2,3} as the maximum value is 3 which occurs twice, and 2 also occurs twice (but 1 occurs 3 times). For full marks,...
a)Write a Python function product(a, b) that recursively computes and returns the value of a times b. Use only the addition operator, and do not use any loops. You can assume that both parameters are non-negative integers. b)Use induction to prove that your algorithm from the previous part is correct
1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...