Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) ListBasics.py A) (10 Points) Write a for loop that iterates over a list of nu

ID: 3837404 • Letter: 1

Question

1) ListBasics.py A) (10 Points) Write a for loop that iterates over a list of numbers num_list and prints the numbers in the list whose square is divisible by 8. For example, if num_list is [2, 3, 4, 5, 6, 7, 8, 9], then the numbers 4 and 8 should be printed.

B) (10 Points) Given list_a = [30, 1, 12, 14, 10, 0] a) How many elements are in lst? b) What is the index of the first element in list_a? c) What is the index of the last element in list_a? d) What is list_a[2]? e) What is list_a[-2]?

C) (20 Points) 10.6 Given list_1 = [3, 1, 2, 4, 0], what is the return value of each of the following statement? a) [x for x in list_1 if x > 1] b) [x * x for x in list_1] Using list comprehension, create the following lists c) [10, 8, 6, 4, 2] d) [0, 2, 4, 6, 8]

D) (10 Points) What are list_x and list_y after the following lines of code? List_x = [1, 43] List_y = [x for x in list_x] List_x[0] = 22

Explanation / Answer

""" Author:ravi Date :10/3/17 File Name:ListBasics.py Description: """ ############### ANSWER(A)############### num_list = [2, 3, 4, 5, 6, 7, 8, 9] for x in num_list: if x ** 2 % 8 == 0: print(x) ############### ANSWER(B)############### # answer(a) list_a = [30, 1, 12, 14, 10, 0] print("Number of element in list_a:", len(list_a)) # answer(b) # index of first element is 0 # answer(c) # index of last element is 5 # answer(d) # list_a[2] is 12 print(list_a[2]) # answer(d) # list_a[-2] is 10 print(list_a[-2]) ############### ANSWER(C)############### list_1 = [3, 1, 2, 4, 0] # answer(a) y = [x for x in list_1 if x > 1] print(y) # [x for x in list_1 if x > 1] =[3,2,4] # answer(b) z = [x * x for x in list_1] print(z) # [x * x for x in list_1]=[9, 1, 4, 16, 0] # answer(c) w = [2 * i for i in range(5, 0, -1)] print(w) # answer(d) v = [i for i in range(0, 9, 2)] print(v) ############### ANSWER(D)############### List_x = [1, 43] List_y = [x for x in List_x] List_x[0] = 22 print(List_x) print(List_y) # List_x=[22, 43] # List_y=[1, 43]