Test Driver

  • Write a function to complete each of the following tasks. Test the function with a test driver.
  1. Function name: compareSum which receives the reference to a tuple with 15 elements. Compute the sum of the first 5 elements and the sum of the last 5 elements. If the sum of the first 5 elements is larger than that of the last 5 elements, print the message “Sum of first five elements is larger.” If the sum of the first 5 elements is the same as that of the last 5 elements, print the message “No difference.” Otherwise, print the message “Sum of first five elements is smaller.”
  2. Function name: printEvenIndex which receives the reference to a tuple with 15 elements. Return the index of those elements which are even integers.
  3. Function name: printThirdIndex which receives the reference to a tuple with 15 elements. Return the index of the third integer which is greater than 3.
  4. Function name: calculateAverage which receives the reference to a tuple with 15 elements. Return the average of the integers stored in the tuple.
  5. Function name: calculatePercent which receives the reference to a tuple with 15 elements. Return the percent of those elements whose indexes are not divisible by 3 or 4.
  6. Function name: countAboveAverage which receives the reference to a tuple with 15 elements. Return the number of elements which are greater than the average of the integers in the tuple.
  7. Function name: calculateRange which receives the reference to a tuple with 15 elements. Return the range of the integers stored in the tuple. The range is defined as the difference between the largest integer and the smallest integer in the tuple.
  8. Write a function named addPositive which has one parameters: numbers (a tuple consisting of integers). The function returns the sum of positive integers stored in the tuple.
  9. Write a function named findIndex which has two parameters: a tuple of integers named numbers and k (a positive integer). The function returns the location of the first integer in the tuple which is less than k. If none of the element in the tuple is less than k, the function returns -9.
  10. Write a function named findSecondLargest which has one parameter: numbers (a tuple containing distinct integers). The function returns the second largest value in the tuple.
  11. Write a function named shiftRight which accepts a list of integers named numbers. The function shifts elements to the right by one position and the last one to the front. That is, numbers[0] → numbers[1], numbers[1] → numbers[2], …, numbers[size-2] → numbers[size-1], and numbers[size-1] → numbers[0], where size is the number of elements in the list. Print the original list and the new one to check to see if the list elements are shifted down correctly.
  12. Write a function named exchange which accepts an list of integers named numbers. The function exchanges elements in the following manner: numbers[0] is exchanged with numbers[size-1], numbers[1] is exchanged with numbers[size-2], number[2] is exchanged with numbers[size-3], etc., where size is the number of elements in the list.
  13. Write a function named isLarger which has two parameters: first and second (both are tuples of integers). The function returns a 1 if the largest value in the first tuple is larger than the largest value in the second tuple; it returns 0 if both largest values are the same; it returns -1 if the largest value i

Need help with this assignment or a similar one? Place your order and leave the rest to our experts!

Quality Assured!

Always on Time

Done from Scratch.