) Scripting and Programming -
Foundations | Questions and Verified Answers
| 100% Correct | Grade A
Correct answer in bold; short rationale follows.
1. Which of the following is the correct way to create a Python list named nums
with the values 1, 2, and 3?
A. nums = (1, 2, 3)
B. nums = {1, 2, 3}
C. nums = [1, 2, 3]
D. nums = 1, 2, 3
Rationale: Square brackets create lists in Python.
2. What is the type of the expression in Python 3?
A. int
B. float
C. str
D. bool
Rationale: Division / produces a float (1.5) in Python 3.
3. Which operator tests equality in Python?
A. =
B. ==
C. ===
D. :=
Rationale: == compares values; = assigns.
, 4. What is printed by this code?
for i in range(3):
print(i, end="")
A. 1 2 3
B. 012
C. 012
D. 0 1 2
Rationale: range(3) yields 0,1,2; end="" prints without spaces/newlines, so
012.
5. Which data structure provides key-value mapping?
A. List
B. Tuple
C. Dictionary
D. Set
Rationale: Dictionaries map keys to values ({key: value}).
6. What does len("hello") return?
A. 4
B. 5
C. 6
D. Error
Rationale: "hello" has 5 characters.
7. Which statement correctly defines a function that takes one argument x?
A. function f(x):
B. def f(x):
C. func f(x):
D. def f => x:
Rationale: def is used to define functions.