Question: (Python 3.5) Purpose: To practice testing for functions you write yourself. For each of the following, implement the stated function, and test it: a) The

(Python 3.5) Purpose: To practice testing for functions you write yourself. For each of the following, implement the stated function, and test it:

a) The function closest_to_zero3(num1, num2, num3) returns value closest to zero from its 3 inputs. For example, given the numbers 2,7,0, the number closes to 0 is 0. For another example, number closest to 0 when comparing 3,-1,5 is -1. Hint: the abs() function may be useful for this question.

b) The function more_odds_than_even(num_list) returns True if the sum of all integers from num_list in odd numbered indices is greater than the sum of all integers of even numbered indices. For example, the function should return False for the list [1,2,3] (Index positions 0 and 2 give the sum of 4 (1+3), and index position 1 gives the sum of 2) and True for the list [1,2] (There is only one even index position (0), and one odd index position(1), and 2 > 1).

Solution Code:

def closest_to_zero(num1, num2, num3): '''  n1, n2, n3 represent numeric values  returns value closest to 0 from 3 input values  '''  tmpnum1 = abs(num1) tmpnum2 = abs(num2) tmpnum3 = abs(num3) if tmpnum1 < tmpnum2 and tmpnum1 < tmpnum3: print(num1) elif tmpnum2 < tmpnum3 and tmpnum2 < tmpnum1: print(num2) else: print(num3) return  def more_odds_than_even(num_list): '''  Returns True if the sum of all integers from num_list is greater then the sum of all integers.  '''  evensum = 0 oddsum = 0 for index in range(len(num_list)): if index % 2 == 0: evensum = evensum + num_list[index] else: oddsum = oddsum + num_list[index] if oddsum > evensum: print("True") else: print("False") return 

I was wondering if someone can please help me develop test cases for this code. I am very stuck at this point as I am new to programming. I would require three White Box and Black Box test-cases. Thank You

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!