Question: PYTHON You MUST use the functions defined in parts (1) and (2) in completing parts (3) and (4) in order to earn full credit for

PYTHON

You MUST use the functions defined in parts (1) and (2) in completing parts (3) and (4) in order to earn full credit for these questions.

(1) Write the definition of a function with the following specification:

squareEach(nums) nums is a list of numbers. Modifies the list by squaring each entry.

If nums =[1,2,4], then nums has the value [1,4,16] after squareList(nums) is called.

(2) Write the definition of a function with the following specification:

toIntegers(aList) aList is a list of strings that represent integers (e.g., ['1','2','4']). Returns a list containing all the values in aList changed to integer values. aList must not be modified.

toInteger(['1','2','4']) returns the value [1,2,4].

(3) Add to the existing program so that toIntegers() is used to return a list composed of all input strings contained in inputListconverted to integers and store the returned list in a list called numbers. Print numbers.

The code for this part must be written under the comment: # ADD CODE FOR PART (3) HERE.

The input

1 2 3 4 

gives the output

Enter a whole number: Enter a whole number: Enter a whole number: Enter a whole number: [1,2,3,4] 

(3) Add to the existing program so that squareList() is called to square each entry in the list numbers. Print numbers.

The code for this part must be written under the comment: # ADD CODE FOR PART (4) HERE.

If the input is

1 2 3 4 

the output ends with

[1,2,3,4] [1,4,9,16] 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------

# Define squareList below

# Define otIntegers below

# main program if __name__ == '__main__': inputList = [] #DO NOT MODIFY THE FOR LOOP BELOW for i in range(4): inputList.append(input('Enter a whole number: ')) # ADD CODE FOR PART (3) HERE # ADD CODE FOR PART (4) HERE

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!