MULTIPLE CHOICE QUESTIONS
- Which of the following loops will always run at least once in most programming languages (but not in Python)?
a. for
b. while
c. do-while
d. infinite - What will
print(range(5))display in Python?
a. [0,1,2,3,4]
b. range(0, 5)
c. [1,2,3,4,5]
d. 5 - In an if-else ladder, how many conditions can be True at a time?
a. 0
b. 1
c. more than 1
d. unlimited - Which statement can be used inside loops to skip directly to the next iteration?
a. break
b. continue
c. skip
d. exit - If a while loop condition is always True, the loop becomes:
a. controlled loop
b. finite loop
c. infinite loop
d. empty loop
FILL IN THE BLANKS
- A ______ loop is useful when we know exactly how many times to repeat.
- The body of an if statement executes only if the condition evaluates to ______.
- Nested loops mean having a loop ______ another loop.
- In a for loop, the stop value is always ______ in the output.
- The keyword used to terminate a loop immediately is ______.
DESCRIPTIVE QUESTIONS
- Write the difference between while loop and for loop with examples.
- What is a nested loop? Give an example program to display a 3×3 square of
*. - Explain the use of the
elseblock with loops in Python. Give an example. - Why do we need conditional statements in programming? Give a real-life example.
- Write an algorithm to find the sum of all even numbers between 1 and N.
PROGRAMMING QUESTIONS
- Write a program to print numbers from 10 down to 1 using a while loop.
- Write a program that takes 5 numbers as input and prints the largest.
- Write a program to check whether the entered number is odd or even.
- Write a program that calculates the factorial of a number entered by the user.
- Write a program to display the squares of numbers from 1 to 10.
Answer Key
MULTIPLE CHOICE QUESTIONS
- c. do-while
- b. range(0, 5)
- b. 1
- b. continue
- c. infinite loop
FILL IN THE BLANKS
- for
- True
- inside
- excluded
- break
DESCRIPTIVE QUESTIONS
- Difference between while and for loop
forloop → used when number of iterations is known.whileloop → used when number of iterations depends on a condition.
for i in range(5): print(i) # runs 5 timesi = 0 while i < 5: print(i) i += 1 - Nested loop example
A loop inside another loop. Example:for i in range(3): for j in range(3): print("*", end=" ") print()Output:* * * * * * * * * - Else with loop
- The
elsepart executes only if the loop completes normally (not terminated bybreak).
for i in range(3): print(i) else: print("Loop finished") - The
- Need for conditional statements
- They allow decision-making in programs.
- Example: ATM machine → If PIN is correct → allow withdrawal, else show error.
- Algorithm for sum of even numbers 1–N
- Start
- Input N
- Initialize sum = 0
- For i = 1 to N:
If i is even → add to sum - Print sum
- End
PROGRAMMING QUESTIONS
- Countdown 10–1
i = 10 while i >= 1: print(i) i -= 1 - Largest of 5 numbers
largest = None for i in range(5): num = int(input("Enter number: ")) if largest is None or num > largest: largest = num print("Largest is:", largest) - Odd or Even
num = int(input("Enter a number: ")) if num % 2 == 0: print("Even") else: print("Odd") - Factorial of a number
num = int(input("Enter a number: ")) fact = 1 for i in range(1, num+1): fact *= i print("Factorial:", fact) - Squares of 1–10
for i in range(1, 11): print(i, "squared is", i*i)
