Here is class 12 computer science Unit 9 [Type B] solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 9 and for all chapters here.Watch all video tutorials for chapter 9: Data Structures – 1 Linear Lists.
Output: [2, 5, 1, 7, 3, 6, 8, 9, 2, 5, 1, 7, 3, 6, 8, 9] No, this code will just duplicate and add the list not as the desired purpose in question.
To make the code to work according to the purpose. SqLst = [2*i for i in NumLst]
SqLst = sorted([2*i for i in NumLst])
The code for above condition [i for i in ML if(i%2 == 0)] Output: [4, 16, 36, 64, 100]
[i for i in ML if(i%2 != 0)]
gen = [] for i in [0, 9, 21, 32]: gen.append(i/2) print(gen)
Output: (i) False (ii) True
Output: 5 [21, 12] 3 5 [21, 12] 3 [21, 12] 31 2
ages = [11, 14, 15, 17, 13, 18, 25] print(ages) Elig = [x for x in ages if x in range(12, 18)] print(Elig)
Solution:
Indentation error
L1 = [x**2 for x in range(10) if x%3 == 0] L2 = L1 L1.append(len(L1)) print(L1) print(L2) L2.remove(len(L2)-1) print(L1)
Output: [0, 9, 36, 81, 4] [0, 9, 36, 81, 4] [0, 9, 36, 81]
def even(n): return n%2==0 list1 = [1,2,3,4,5,6,7,8,9] ev = [n for n in list1 if n%2==0] evp = [n for n in list1 if even(n)] print(evp)
Output: [2, 4, 6, 8]
(i) b = [[9,6], [4,5], [7,7]] x = b[:2] x.append(10) print(x) (ii) b = [[9,6], [4,5], [7,7]] x = b[:2] x[1].append(10) print(x)
Output:
(i) [[9, 6], [4, 5], 10] (ii) [[9, 6], [4, 5, 10]]
The code will cause error if ch is 2 because then value 100 being absent in Lst1 and Lst2 and its index being asked. Also, the error will encounter on ch is 3 as Lst2 is empty and underflow case (nothing to pop out) arise.
# corrected code Lst1 = [23, 34, 12, 77, 34, 26, 28, 93, 48, 69, 73, 23, 19, 88] Lst2 = [] print("List1 original is :", Lst1) ch = int(input("Enter 1/2/3 and predict which operation was performed?")) if ch == 1: Lst1.append(100) Lst2.append(100) elif ch == 2: if Lst1.count(100) >0: print(Lst1.index(100)) if Lst2.count(100) >0: print(Lst2.index(100)) elif ch == 3: print(Lst1.pop())
(i) The if statement is called twice and list comprehension is called in incorrect way #correct code [y for y in range(100) if (y % 2 == 0 and y % 5 == 0)] (ii) The twice if statement # correct code (y for y in range(100) if (y % 2 == 0 and y % 5 == 0 ))
#correct code ["good" if i < 3 else "better" for i in range(6)] No requirement of the colon in list comprehension.
Q15: (i) The if statement is called twice and list comprehension is called in incorrect way #correct code [y for y in range(100) if (y % 2 == 0 and y % 5 == 0)] (ii) The twice if statement is the error in this case. # correct code (y for y in range(100) if (y % 2 == 0 and y % 5 == 0 )) Q16: #correct code ["good" if i < 3 else "better" for i in range(6)] No requirement of the colon in list comprehension.
Clear Doubts with Computer TutorIn case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in
You cannot copy content of this page