Define an empty list named values (please note that in rest of the questions if you see
Question:
Define an empty list named values (please note that in rest of the questions if you see this name of list then it means this same list created here). Run your cell so that this list gets defined by interpretor and is available in the rest of cells.
b. Demonstrate code that fills the list values with all the integers from 1 to 1000.]
c. Demonstrate code to empty the list values populated with numbers in last question by using a list method.
d. Demonstrate code that fills the list values with the set of numbers below using two different ways
- 1 4 9 16 25 36 49 64 81 100
e. Demonstrate code that first deletes all old elements from values list and then fills it with 100 random integers chosen between 1 to 500.
Question 2: Acessing List Elements
Assume scores is a list of integers. Fill in the following code snippets
a. Define and fill the list scores with 100 random integer values and then print all values on even indices of this list.
b. Demonstrate code that increments by 2 (1 becomes 3, 2 becomes 4 etc) all values on odd indices of the list scores from last question.
c. Write code that will replicate value of scores[50] into the first 10 elements of scores list (this means after your code is executed first 10 elements of score will be same as the value of scores[50]
d. Demonstrate code that automatically verifies that first 10 elements of the list scores have the same value as that of scores[50]. Print "Same numbers!" if numbers are same else print "Not all numbers are the same." (continuation of last question)
e. Set variable size to contain the number of elements in the scores list
f. Give two different methods of accessing and printing all elements of list one by one on a single line using for loop. One method should make use of list index, the other method should not use the index.
Ex. #Code Here
#First method
#Second method
Question : List Alias and List Copy and Mutability
a. What is the difference between creating an alias of the list vs creating a copy of the list. Give one example of each. You can show explanation.
b. Show an example of creating an alias of a list and creating the copy of a list
c. Write down the definition of a mutability and an immutability. Write examples of a mutable data type & a immutable data type. Show that why they are mutable and immutable.
Question 4: Common List Algorithms
a. Demonstrate a program where you ask user to input integers in a loop. Save these numbers in the list user_values and Quit taking the input when user enters "Q" or "q". Demonstrate a for loop that iterate over the elements of this list for the following tasks.
- Find the maximum of the numbers in the list
- Find the minimum element from the list
- Compute the average of all the elements
- Computing the sum of all elements in the list.
- Counting how many elements in a list are negative.
Avoid using more than one loop, you can use builtin functions where possible.
a. Modify the code in question 4.a to do the computations in a separate function named ListStats. This function should take reference to the list and should return a tuple of 5 stats computed in previous question.