Reference no: EM132356659
Question
Write a Python program that defines and exercises four functions. • Function 1 (lists): Write a function that solves the following problem PARAMETERS: A list of integers and an integer x RETURNS: The number of integers in the list that are greater than x.
This function's header might look like this def greaterThanX(myList, x):
Write a test program that prompts the user to enter a list of integers and an integer x. Invoke the function to return the number of integers in the list that are greater than x. Display this number.
Function 2 (lists): Write a function that solves the following problem PARAMETERS: A list of integers RETURNS: The index of the smallest element in the list. If the number of such elements is greater than 1, return the smallest index.
This function's header might look like this def indexOfSmallest(myList):
Write a test program that prompts the user to enter a list of integers. Invoke the function to return the index of the smallest element in the list. Display the index.
Function 3 (files): Write a function that writes an x number of integers created randomly into a file. Integers are separated by a space in the file. Read the data back from the file and display the average. PARAMETERS: x RETURNS: The average of the random integers
This function's header might look like this def randomAverage(x):
Write a test program that prompts the user to enter x. Invoke the function to generate x random numbers, write them to a file, and compute the average. Display the average
Function 4 (files): Write a function that counts the number of words in a text file of your choosing. Parameters: a file name and a word w to be found RETURNS: The number of occurrences of w in the file
This function's header might look like this def wordCount(myFile, w):
Write a test program that prompts the user to enter the name of the file and the word to be counted. Invoke the function and display the word count.