Week-05 Assessment: Sample Questions

[ Question 1 ] [ Question 2 ]


Question 2

Your task is to write a Python code segment that works on a Python list of numbers. Assume that you are given a Python list with float type and we will refer to this list as list_a. Your program will use list_a to produce another Python list, which we will refer to as list_b. These two lists are expected to have the same length, and the entries these two lists are related by:

list_b[0] = cos(list_a[0])
list_b[1] = cos(list_a[1])
list_b[2] = cos(list_a[2])
....

The following Python code segment should produce list_b as described above.

Please fill the blanks below, and importantly briefly justify your answers to you tutor.

import math

list_b = _____1_____
for _____2_____ : 
    list_b.append(_____3_____)


Answers (also provide brief justifications):

1) [ ]
2) k in list_a 
3) math.cos(k)