Use of procedures, parameter passing, block structures, data types, arrays, abstract data structures, conditional control, iterative and recursive processes, and input/output in programming solutions to a variety of problems. Prerequisite: None.

Lab 5 - Introduction to Lists - (50 points)



Due date: 3/23/2019 at 11:59pm

Objectives



  • Practice with lists
  • Practice with functions
  • Learn about function parameters

List Operations



Write a program (listoperations.py) that contains 10 numbers. You do not need user input for this part of the lab. The list must be defined and initialized in the main() function. You cannot use any global variables. Show the user a menu that asks the user which of the following operations they would like to perform on the list. Perform input validation and based on the user choice, execute the appropriate function and display the result. Here are the function signatures along with a description of the expected behavior.

  • Find lowest element in a list - def findLowest(listName): This function takes in the list of numbers as input and returns the lowest number in the list.
  • Compute the Average - def computeAverage(listName): This function takes in the list of numbers as input and returns the average of all the numbers in the list.
  • Drop every Nth element - def dropEveryNthElement(listName, N): This functions takes in the list of numbers and a value N and returns a list with every Nth element from the list dropped from the list. For example, with an input list of [1, 2, 3, 4, 5, 6, 7] and N = 3, the returned list will be [2, 3, 5, 6].
  • Eliminate Duplicates - def eliminateDuplicates(listName): This function takes in the list of numbers and returns a list that does not contain any duplicate numbers in the list. For example, if the input list is [1, 2, 2, 3, 2], this function must return [1, 2, 3].
  • Duplicate N times - def duplicateNtimes(listName, count): This function takes in the list of numbers and a count for duplication. It returns a list that is count times longer than the original list and contains count number of entries for each entry in the original list (listName). For example, if the input list is [1, 2, 3] and count is 3, then the function will return a list that looks like this - [1, 1, 1, 2, 2, 2, 3, 3, 3]. Make sure to test the function for various values of count.

Extra credit



  • Rotate Left by Ndef rotateLeftN(listName, N): (2 points) - This function takes in the list of numbers and a value for rotation and returns the input list leftwards N times. For example, for an input list of [1, 2, 3, 4, 5, 6] and N=4, the function will return the following list [5, 6, 1, 2, 3, 4]. Test the function for various values of N.

Submitting the lab



Submit the following files on Canvas

  • listoperations.py
  • README file