Computational Thinking, Quiz 1
Let L be a non-empty list of integers, and D be a non-empty dictionary which are given below:
L = [-2, -1, 0, 1, 2]
D = {-2: 'a', 2: 'b', -1: 'c', 1: 'd', 0: 'e'}
Match the following expressions on the left side with the appropriate values on the right side.
a. D['a']
b. keys(D)
c. isKey(D, 1)
d. first(init(L)) + last(rest(L))
e. first(rest(L)) + last(init(L))
f. last(init(init(L)))
Let **L** be a non-empty list of integers, and **D** be a non-empty dictionary which are given below: **L** = [-2, -1, 0, 1, 2]\ **D** = {-2: 'a', 2: 'b', -1: 'c', 1: 'd', 0: 'e'} Match the following expressions on the left side with the appropriate values on the right side. a. **D**['a']\ b. **keys(D)**\ c. **isKey(D, 1)**\ d. **first(init(L))** + **last(rest(L))**\ e. **first(rest(L))** + **last(init(L))**\ f. **last(init(init(L)))** 1. True 2. Invalid key 3. **L** 4. 0 5. -1 6. A list The following pseudocode is executed using the "Scores" dataset. Let **sum** be a procedure which takes a list as input and returns the sum of the elements of the list. What will **A** represent at the end of the execution? cityD = { } while (Table 1 has more rows) { Read the first row X in Table 1 if (isKey(cityD, X.CityTown)) { if (isKey(cityD[X.CityTown], X.Gender)) { cityD[X.CityTown][X.Gender] = cityD[X.CityTown][X.Gender] ++ [X.Physics] } else { cityD[X.CityTown][X.Gender] = [X.Physics] } } else { cityD[X.CityTown][X.Gender] = [X.Physics] } Move row X to Table 2 } A = 0 foreach i in keys(cityD) { P = findSomething(cityD[i]['M'], cityD[i]['F']) if (P) { A = A + 1 } } Procedure findSomething(l1, l2) p = sum(l1)/length(l1) q = sum(l2)/length(l2) if (q > p) { return (True) } else { return (False) } End findSomething Choose the correct option based on the following pseudocode in the given subquestions. L = [0] LA = [[1], [1, 2], [1, 2, 3]] LB = [ ], LC = [ ] foreach A in LA { foreach B in A { LB = [B] ++ LB L = [first(L) + B] } LC = [LB] ++ LC LB = [ ] } What will be the value of **L** at the end of execution?