What does sequencing mean in a program?
Order in which code instructions are executed.
What keyword starts a conditional statement in Python?
if
What does a loop do?
Repeats a set of instructions.
What is a function?
A named block of code that performs a task.
What is abstraction in computer science?
Simplifying complex systems by hiding details.
What is the output?
x = 5
x = x + 2
print(x)
7
What is the output?
x = 10
if x > 5:
print("Big")
Big
How many times does this loop run?
for i in range(3):
print(i)
3 times (prints 0, 1, 2)
What does this function return?
def double(x):
return x * 2
print(double(3))
6
How does abstraction help in programming?
Makes it easier to understand and manage large programs.
What happens if you call a variable before it is assigned a value?
Causes a runtime error
When is an else clause executed?
When all preceding if and elif conditions are false.
What’s the output?
count = 0
while count < 3:
print(count)
count += 1
0, 1, 2
Why are functions useful?
They allow code to be reused and keep programs organized
Why do programmers create custom functions for repeated tasks?
To reduce code repetition and increase modularity.
Rearrange the steps below to correctly calculate the area of a rectangle:
Print area
Assign area = length * width
Input width
Input length
Input length → Input width → Assign area → Print area
What will this code print?
x = 8
if x < 5:
print("Small")
elif x < 10:
print("Medium")
else:
print("Large")
Medium
Why might this loop run forever?
while True:
print("Hello")
Because True is always true and there's no break condition.
What is the output?
def greet(name):
return "Hello " + name
print(greet(name))
Hello (name)
How would you use abstraction when designing a game?
Create separate functions for movement, scoring, display, etc., instead of writing everything in one place.
A student writes a program where an input comes after the output. What’s the likely problem?
The output might display incorrect or default values because the needed input wasn't available in time.
A student writes this code:
score = 85
if score >= 90:
grade = "A"
if score >= 80:
grade = "B"
print(grade)
Why does it output "B" and not "A"?
Because both if statements are checked independently, not exclusively, no elif.
Predict the output:
for i in range(2):
for j in range(3):
print(i, j)
0 0
0 1
0 2
1 0
1 1
1 2
Fix the error:
def subtract(a, b):
result = a - b
print(result)
return result and then call print(subtract(x, y))
A student wrote all code in one long sequence. How could abstraction improve this?
By breaking it into logical, reusable procedures that make the program more readable, testable, and maintainable.