Question

In: Computer Science

# Finds and returns only the even elements in the list u. # find_evens([1, 2, 3,...

# Finds and returns only the even elements in the list u.
# find_evens([1, 2, 3, 4] returns [2, 4]
# find_evens([1, 2, 3, 4, 5, 6, 7, 8, 9, 10] returns [2, 4, 6, 8, 10]
#
u = [1, 2, 3, 4] 
v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

def find_evens(u):
    return None  # Replace this with your implementation
 
print('Testing find_evens')
print(' find_evens(u): ' + str(find_evens(u)))
print(' find_evens(v): ' + str(find_evens(v)))
print()

Making code using recursion function

In Python

Solutions

Expert Solution

Here, I' m giving you the python code which contains two functions. Once is a recrussive function to check whether a element in list is even or not. And the next one is to pass the entire list from the list data and to give each digit for recrussive function. The code is given below;

#difining two strings for finding even numbers
u = [1, 2, 3, 4] 
v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

#defining recrusion function to check even number or not
def isEven(num):
     if(num<2):
         return (num%2 == 0)
     return (isEven(num-2))

#defining find_evens function
def find_evens(list1):
    
     #calling resrussive function isEven (using list comprehension)
     even_nos = [num for num in list1 if (isEven(num)==True)] 
     return even_nos
    
print('Testing find_evens')
print('find_evens(u): ' + str(find_evens(u)))
print('find_evens(v): ' + str(find_evens(v)))
print()

OUTPUT:


Related Solutions

Summarize and list the elements of the following: 1) Medical Fraud 2)Assault and Battery 3)Defamation of...
Summarize and list the elements of the following: 1) Medical Fraud 2)Assault and Battery 3)Defamation of Character
write the method “getMaxValue” that finds and returns the maximum value in an integer linked list....
write the method “getMaxValue” that finds and returns the maximum value in an integer linked list. If the list is empty, then it should return 0. use the provided code below public class Question03 { public class ListNode//public for testing purposes { public int data;//public for testing purposes public ListNode link;//public for testing purposes public ListNode(int aData, ListNode aLink) { data = aData; link = aLink; } } public ListNode head;//public for testing purposes public int getMaxValue() { //----------------------------------------------------------------------------------- //Write...
Write a Python function which finds the smallest even and odd numbers in a given list....
Write a Python function which finds the smallest even and odd numbers in a given list. (Use for loop and if conditions for this problem)
1. U ( x 1 , x 2 ) = 2 x1 + 3 x 2...
1. U ( x 1 , x 2 ) = 2 x1 + 3 x 2 If the price of good 1 is $4/unit, the price of good 2 is $5/unit , and income is $20... What is this person's optimal consumption level for good 1? 2. U( x 1 , x 2 ) = 5 x1 + 3 x2 If the price of good 1 is $2/unit, the price of good 2 is $1/unit , and income is $10......
E.g., given an array-backed list lst containing the elements [0, 1, 2, 3, 4, ..., 98,...
E.g., given an array-backed list lst containing the elements [0, 1, 2, 3, 4, ..., 98, 99], the following code: for x in lst.poly_iter(2, 3, 4): print(x) will produce the output: 4 9 18 31 48 69 94 Programming rules: You must adhere to the same rules when using the built-in Python list as you did in the ArrayList lab. You may not use any other data structures (this includes the built-in Python list). class ArrayList: def __init__(self): self.data =...
1) Determine the angle between vectors: U = <2, -3, 4> and V= <-1, 3, -2>...
1) Determine the angle between vectors: U = <2, -3, 4> and V= <-1, 3, -2> 2) determine the distance between line and point P: -2x+3y-4z =2 L: 3x – 5y+z =1 3) Determine the distance between the line L and the point A given by L; (x-1)/2 = (y+2)/5 = (z-3)/4 and A (1, -1,1) 4) Find an equation of the line given by the points A, B and C. A (2, -1,0), B (-2,4,-1) and C ( 3,-4,1)...
a) U = xy b) U = (xy)^1/3 c) U = min(x,y/2) d) U = 2x...
a) U = xy b) U = (xy)^1/3 c) U = min(x,y/2) d) U = 2x + 3y e) U = x^2 y^2 + xy 4. All functions except c) are differentiable. Do these functions exhibit diminishing marginal utility? Are their Marshallian demands downward sloping? What can you infer about the necessity of diminishing marginal utility for downward- sloping demands?
write a recursive method that returns the product of all elements in java linked list
write a recursive method that returns the product of all elements in java linked list
1. List the four elements that must be present for a market to exist. 2. What...
1. List the four elements that must be present for a market to exist. 2. What is the market process? 3. What is the difference between demand and want? 4. Briefly explain each of the following: a) The market-size effect b) The real income effect c) The substitution effect 5. Why does a fall in price increase real income? 6. Why is the typical demand curve downward sloping? 7. What are normal goods? Give three specific examples of normal goods....
Which molecules are polar? 1. F2 2. SiF2Cl2 3. SF4 3 only 1, 2 and 3...
Which molecules are polar? 1. F2 2. SiF2Cl2 3. SF4 3 only 1, 2 and 3 1 only 2 only 2 and 3
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT