Python Test Paper (Total: 20 Marks)
Instructions: Attempt all questions. Write clear code and expected outputs. Each question is
worth 2 marks.
Section A: Output Prediction (10 Marks)
Q1. (2 Marks)
What is the output of this code?
python
CopyEdit
for i in range(3):
print(i, end=":")
else:
print("LoopDone")
Q2. (2 Marks)
Predict the result of the following:
python
CopyEdit
x=5
y = 12
x = x + y / 3 + y // 5
print(x)
Q3. (2 Marks)
What does this print?
python
CopyEdit
i=1
while i < 5:
i=i*2
print(i)
Q4. (2 Marks)
Determine the output:
python
CopyEdit
i = "7"
for ch in i:
print(ch)
Q5. (2 Marks)
What is the output of this program?
python
CopyEdit
x = 987
while x % 10:
x = x // 10
print(x)
These are inspired by classic output-based loop examples CS-IP-Learning-Hub+1.
Section B: Programming Tasks (10 Marks)
Q6. (2 Marks)
Write a program that:
Takes a single character as input.
Prints the character.
On the next line, prints its ASCII code (using ord()).
Q7. (2 Marks)
Write a while loop program that starts with n = 1, prints n, doubles it each time, and stops
once n becomes greater than 500. Finally, print "Finished".
Q8. (2 Marks)
Ask the user to enter an integer n. Use a loop to print all perfect squares (1, 4, 9, ...) that are
≤ n, then print "Done" after the loop.
Q9. (2 Marks)
Prompt for an integer n. Use a while loop to print Fibonacci sequence numbers (starting 0, 1,
1, 2, …) that are ≤ n. Once the next Fibonacci number would be greater than n, stop and
print "Complete".
Q10. (2 Marks)
Read a student's marks (0–100). Use if-elif-else to print:
A for marks ≥ 90
B for marks ≥ 80
C for marks ≥ 70
D for marks ≥ 60
F for marks below 60