Question: Exercise 2 Write a function scalarAdd which takes a list of numbers lst and a number num as parameters. The function should modify lst by

 Exercise 2 Write a function scalarAdd which takes a list of

Exercise 2 Write a function scalarAdd which takes a list of numbers lst and a number num as parameters. The function should modify lst by adding num to all the elements of lst. The function should not return anything. Call the function in the main program to do few tests, as per the below sample runs: Initial list 1:[0,1,2,3,4,5,6,7,8,9] Value of 1 after applying saclarAdd (1,):[0,1,2,3,4,5,6,7,8,9] Value of 1 after applying saclarAdd (1,1):[1,2,3,4,5,6,7,8,9,10] Value of 1 after applying saclarAdd (1,2):[3,4,5,6,7,8,9,10,11,12] Value of 1 after applying saclarAdd (1,3):[6,7,8,9,10,11,12,13,14,15] Value of 1 after applying saclarAdd (1,4):[10,11,12,13,14,15,16,17,18,19] Exercise 3 Write a function randList with a parameter size, that returns the a list composed of the integers between 1 and size in random order (each number should appear exactly once). Call if from the main function to check that it works. Hint: recall the shuffle function of the random module. What is the size of the random matrix you want? 18 [9,1,16,18,4,14,13,11,15,12,2,7,3,8,10,17,5,6] >>> What is the size of the random matrix you want? 18 [6,13,1,7,14,5,9,8,3,16,10,11,15,4,12,18,17,2] Exercise 4 Given a list, it is easy to find the minimal element. The goal of this exercise is to write a function that returns not only the smallest element but the k smallest ones in ascending order (where k is an integer more than 1). In case k is less than the number of elements of the list, the function should return all the elements of the list. The function should not modify the initial list! To test your code, use the below main program: test =[2,7,9,3,6,5,1,1,2,9] test 2=[2,7,3,3] print( "First test:") print("Before function:", test) print("Five smallest: ", kMin(test, 5)) print("After function:", test) print( "Second test:") print( "Before function:", test2) print("Five smallest: ", kMin(test2, 5)) print( "After function: ", test2) You should then be able to get the following sample run: First test: Before function: [2,7,9,3,6,5,1,1,2,9] Five smallest: [1,1,2,2,3] After function: [2,7,9,3,6,5,1,1,2,9] Second test: Before function: [2,7,3,3] Five smallest: [2,3,3,7] After function: [2,7,3,3]

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!