QuizSpace

Computational Thinking (CT) week 6 important questions

Week 6 of Computational Thinking: Tables, dictionaries. Extra important questions based on the recent, changing patterns of the exams, from basic to advanced. Practise them in learning mode: each question has a worked solution.

Question 1

Numerical answer

In the pseudocode, a dictionary D is written with curly brackets as key: value pairs. D[k] = v adds the pair or, if k is already a key, replaces its value. "k in D" is true when k is a key of D, length(D) is the number of keys, "delete D[k]" removes the pair, and "for each key k in D" visits every key once.

D = {"apple": 13, "melon": 9, "papaya": 10}
D["apple"] = 2
D["lemon"] = D["apple"] + 1
Print D["lemon"] + D["melon"]

What is printed?

Question 2

One correct option

In the pseudocode, a dictionary D is written with curly brackets as key: value pairs. D[k] = v adds the pair or, if k is already a key, replaces its value. "k in D" is true when k is a key of D, length(D) is the number of keys, "delete D[k]" removes the pair, and "for each key k in D" visits every key once.

D = {"banana": 15, "guava": 18, "grape": 15}
D["grape"] = 7
D["guava"] = 6
D["guava"] = 5
D["banana"] = 4
D["guava"] = 4
Print length(D)

What is printed?

  1. A

    22

  2. B

    44

  3. C

    66

  4. D

    33

Question 3

Numerical answer

In the pseudocode, a dictionary D is written with curly brackets as key: value pairs. D[k] = v adds the pair or, if k is already a key, replaces its value. "k in D" is true when k is a key of D, length(D) is the number of keys, "delete D[k]" removes the pair, and "for each key k in D" visits every key once.

D = {"melon": 18, "guava": 12, "lemon": 12}
delete D["guava"]
c = 0
if ("melon" in D) { c = c + 1 }
if ("guava" in D) { c = c + 10 }
if ("apple" in D) { c = c + 100 }
Print c + length(D)

What is printed?

More questions in this week

Authorise with Google to see every question with its answer and explanation and practise it in learning mode.

IMPPractise OPPE 1 PYQs:PythonSystem CommandsJava