A) Write a for loop that iterates over a list of numbers num_list and prints the
ID: 3837459 • Letter: A
Question
A) 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) 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) 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) 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
A) 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.
for x in list_x]:
if (x*x)%8==0:
print x
B) 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]?
THere are 6 elements are in list.
0 is the index of first element(30)
5 is the index of last element(0)
list_a[2] = 12
list_a[-2] = 10
C) 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]
returned value: 3, 2, 4
b) [x * x for x in list_1]
9, 1, 2, 16, 0
Using list comprehension, create the following lists
c) [10, 8, 6, 4, 2]
list_c = [10, 8, 6, 4, 2]
d) [0, 2, 4, 6, 8]
list_d = [0, 2, 4, 6, 8]
D) 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
List_x = [22, 43]
List_y = [1, 43]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.