Exam (Python)
Section 1: Multiple Choice Questions (2 points each)
What is the output of the following code?
python
Copy
x=5
y=2
print(x // y)
a) 2.5
b) 2
, c) 3
d) 2.0
Answer: b) 2
Which of the following is NOT a valid Python variable name?
a) my_var
b) _var
c) 2var
d) var2
Answer: c) 2var
What does the range(1, 10, 2) function generate?
a) [1, 3, 5, 7, 9]
b) [1, 2, 3, 4, 5, 6, 7, 8, 9]
c) [2, 4, 6, 8, 10]
d) [1, 3, 5, 7, 9, 11]
Answer: a) [1, 3, 5, 7, 9]
What is the output of the following code?
python
Copy
my_list = [1, 2, 3, 4, 5]
print(my_list[1:4])
a) [1, 2, 3]
b) [2, 3, 4]
c) [1, 2, 3, 4]
d) [2, 3, 4, 5]