Computational Thinking, Quiz 2
Let L be a non-empty list of integers, and D be a non-empty dictionary which are given below:
L = [8, -4, 10, 4, -6]
D = {1: {"Name": "John", "Age": 12, "Gender": 'M'}}
Match the following expressions on the left side with the appropriate values on the right side.
| a. member(L, 10) | 1. 12 |
|---|---|
| b. isKey(D, "Name") | 2. 10 |
| c. D[1]["Age"] | 3. [1] |
| d. first(L) + last(init(L)) | 4. False |
| e. first(rest(rest(L))) | 5. True |
| f. keys(D) | 6. Invalid expression |
Let **L** be a non-empty list of integers, and **D** be a non-empty dictionary which are given below:\ **L** = [8, -4, 10, 4, -6]\ **D** = {1: {"Name": "John", "Age": 12, "Gender": 'M'}}\ Match the following expressions on the left side with the appropriate values on the right side. | a. **member(L, 10)** | 1. 12 | |---|---| | b. **isKey(D, "Name")** | 2. 10 | | c. **D**[1]["Age"] | 3. [1] | | d. **first(L)** + **last(init(L))** | 4. False | | e. **first(rest(rest(L)))** | 5. True | | f. **keys(D)** | 6. Invalid expression | The given pseudocode is executed using the "Words" dataset. **C** stores the number of adjectives which have at least one noun adjacent to it. Choose the correct code fragment to complete the pseudocode. A = [ ], N = [ ] while (Table 1 has more rows) { Read the first row X in Table 1 if (X.PartOfSpeech == "Adjective") { A = A ++ [X.SeqNo.] } if (X.PartOfSpeech == "Noun") { N = N ++ [X.SeqNo.] } Move X to Table 2 } ******************** * Fill the code * ******************** **trains** is a dictionary with train number as key mapped to a list of stations which that train runs through. For example, **trains** = { 12281: ["Bhubaneswar","Balasore", "Adra", "Varanasi", "Kanpur", "New Delhi"],......}. In this example, the train with train number 12281 starts from Bhubaneswar and reaches New Delhi via Balasore, Adra, Varanasi, and Kanpur. At the end of execution of the code below, **L** stores the names of stations through which the maximum number of trains pass. Choose the correct fragment to complete the pseudocode.\ It is a Multiple Choice Question. (MCQ). stns = { }, N = 0, L = [ ] foreach X in keys(trains) { stns = updateDictionary(stns, X) } foreach Y in keys(stns) { ******************** * Fill the code * ******************** } Procedure updateDictionary(D, Z) foreach A in trains[Z] { if (not isKey(D, A)) { D[A] = 1 } else { D[A] = D[A] + 1 } } return (D) End updateDictionary