User Tools

Site Tools


submissions:assesment:52960:assement2

MPP - Assignment 2 (15%)

Tasks

For each of the following write a functional, recursive, function in Python to accomplish the task. Marks will be award for correct solutions and for comments explaining how the function works.

  1. Sum of an array Given an array of numbers return it’s sum (all the numbers added together).
  2. Product of an array Given an array of numbers return it’s product (all the numbers multiplied together).
  3. Remove all odd numbers Given an array of numbers return an array with all the odd numbers removed.
  4. Remove all even numbers Given an array of numbers return an array with all the even numbers removed.
  5. Replace a given character with ’*’ Given a string, and a character to replace, return a string where each occurance of the character is replaced with ’*’.
  6. Find index in array for item. Given an array, and an element to search for return the index of the element in the array or -1 if the element is not present in the array.
  7. Sum of Digits Given a whole, number such as 23, return the sum of the digits in the number i.e. 2 + 3 = 5. For this would be useful to convert the number to a string then break it apart into digits.
  8. Print an array Given an array of integers prints all the elements one per line. This is a little bit different as there is no need for a ’return’ statement just to print and recurse.
  9. Find the minimum element in an array of integers. You can carry some extra information through method arguments such as minimum value.
  10. Verify the parentheses Given a string, return true if it is a nesting of zero or more pairs of parenthesis, like “(())” or “((()))”.
submissions/assesment/52960/assement2.txt · Last modified: 2020/06/20 14:39 by 127.0.0.1