Python Class 7 Practice Questions SET 2 – If Condition, Loops, Range & Programming Exercises

MULTIPLE CHOICE QUESTIONS

  1. 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
  2. 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
  3. In an if-else ladder, how many conditions can be True at a time?
    a. 0
    b. 1
    c. more than 1
    d. unlimited
  4. Which statement can be used inside loops to skip directly to the next iteration?
    a. break
    b. continue
    c. skip
    d. exit
  5. 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

  1. A ______ loop is useful when we know exactly how many times to repeat.
  2. The body of an if statement executes only if the condition evaluates to ______.
  3. Nested loops mean having a loop ______ another loop.
  4. In a for loop, the stop value is always ______ in the output.
  5. The keyword used to terminate a loop immediately is ______.

DESCRIPTIVE QUESTIONS

  1. Write the difference between while loop and for loop with examples.
  2. What is a nested loop? Give an example program to display a 3×3 square of *.
  3. Explain the use of the else block with loops in Python. Give an example.
  4. Why do we need conditional statements in programming? Give a real-life example.
  5. Write an algorithm to find the sum of all even numbers between 1 and N.

PROGRAMMING QUESTIONS

  1. Write a program to print numbers from 10 down to 1 using a while loop.
  2. Write a program that takes 5 numbers as input and prints the largest.
  3. Write a program to check whether the entered number is odd or even.
  4. Write a program that calculates the factorial of a number entered by the user.
  5. Write a program to display the squares of numbers from 1 to 10.
Answer Key

MULTIPLE CHOICE QUESTIONS

  1. c. do-while
  2. b. range(0, 5)
  3. b. 1
  4. b. continue
  5. c. infinite loop

FILL IN THE BLANKS

  1. for
  2. True
  3. inside
  4. excluded
  5. break

DESCRIPTIVE QUESTIONS

  1. Difference between while and for loop
    • for loop → used when number of iterations is known.
    • while loop → used when number of iterations depends on a condition.
    for i in range(5): print(i) # runs 5 times i = 0 while i < 5: print(i) i += 1
  2. Nested loop example
    A loop inside another loop. Example: for i in range(3): for j in range(3): print("*", end=" ") print() Output: * * * * * * * * *
  3. Else with loop
    • The else part executes only if the loop completes normally (not terminated by break).
    for i in range(3): print(i) else: print("Loop finished")
  4. Need for conditional statements
    • They allow decision-making in programs.
    • Example: ATM machine → If PIN is correct → allow withdrawal, else show error.
  5. 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

  1. Countdown 10–1 i = 10 while i >= 1: print(i) i -= 1
  2. 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)
  3. Odd or Even num = int(input("Enter a number: ")) if num % 2 == 0: print("Even") else: print("Odd")
  4. Factorial of a number num = int(input("Enter a number: ")) fact = 1 for i in range(1, num+1): fact *= i print("Factorial:", fact)
  5. Squares of 1–10 for i in range(1, 11): print(i, "squared is", i*i)

Leave a Reply

Discover more from Abhyas

Subscribe now to keep reading and get access to the full archive.

Continue reading