– 15 Actual Q&A with Detailed Rationales | 100% Verified |
Pass Guaranteed – A+ Graded
Section A: Fundamentals, Control Flow & Data Structures (10
Multiple-Choice Questions)
Q1: A Python program needs to read a user's age as an integer from keyboard input.
Which code correctly accomplishes this?
A. age = input("Enter age: ")
B. age = int(input("Enter age: ")) [CORRECT]
C. age = str(input("Enter age: "))
D. age = float(input("Enter age: "))
Correct Answer: B
Rationale: input() always returns a string; int() must be called to convert the string
to an integer. Option A leaves age as a string. Option C explicitly converts to string
(redundant). Option D converts to float, not integer.
Q2: Consider the following code:
Python
x = 5
y = 2
, result = x // y
print(result)
What is the output?
A. 2.5
B. 2 [CORRECT]
C. 1
D. 3
Correct Answer: B
Rationale: The // operator performs floor division (integer division), returning the
largest integer less than or equal to the quotient. 5 // 2 equals 2. Option A would
result from (true division). Options C and D are incorrect arithmetic results.
Q3: A function needs to accept any number of positional arguments and store them in a
tuple. Which parameter syntax achieves this?
A. def func(args=[]):
B. def func(*args): [CORRECT]
C. def func(**args):
D. def func(&args):
Correct Answer: B