Python Class 7 Practice Questions SET 1 Answer Key – If Condition, Loops, Range & Programming Exercises

MULTIPLE CHOICE QUESTIONS

  1. b. It executes code only if the condition is True
  2. c. for
  3. a. [2, 4, 6, 8]
  4. b. break
  5. c. while loop

FILL IN THE BLANKS

  1. continue
  2. Boolean (True/False)
  3. 0
  4. backwards / in reverse
  5. single-pass (or one-time) loop

DESCRIPTIVE QUESTIONS

  1. Break vs Continue
    • break → exits the loop completely.
    • continue → skips the current iteration and moves to the next.
    for i in range(1, 6): if i == 3: continue # skip 3 if i == 5: break # stop at 5 print(i) # Output: 1 2 4
  2. Entry-controlled vs Exit-controlled
    • Entry-controlled: condition checked first, then body executes (e.g., Python’s while, for).
    • Exit-controlled: body executes at least once, then condition is checked (e.g., do-while in other languages).
    • Python’s while → entry-controlled loop.
  3. If loop variable not updated
    • The condition may never change, causing an infinite loop.
    i = 1 while i < 5: # infinite loop because i never increments print(i)
  4. Difference in range()
    • range(stop) → counts from 0 to stop-1.
    • range(start, stop, step) → more control with start, stop, and step.
      Example:
    range(5) → [0,1,2,3,4] range(2,10,2) → [2,4,6,8]
  5. Indentation importance
    • Python uses indentation to define blocks. Incorrect indentation → error.
    if True: print("Hello") # ❌ Error: indentation required

PROGRAMMING QUESTIONS

  1. Even numbers 1–50
    • for i in range(2, 51, 2):
    • print(i)
  2. Sum until 0 entered
    • total = 0
    • while True:
    • num = int(input(“Enter a number (0 to stop): “))
    • if num == 0:
    • break
    • total += num
    • print(“Sum is:”, total)
  3. Check prime number
    • num = int(input(“Enter a number: “))
    • if num > 1:
    • for i in range(2, num):
    • if num % i == 0:
    • print(“Not Prime”)
    • break
    • else:
    • print(“Prime”)
    • else:
    • print(“Not Prime”)
  4. Count vowels in string
    • text = input(“Enter a string: “)
    • vowels = “aeiouAEIOU”
    • count = 0
    • for ch in text:
    • if ch in vowels:
    • count += 1
    • print(“Number of vowels:”, count)
  5. Multiplication table
    • num = int(input(“Enter a number: “))
    • for i in range(1, 11):
    • print(num, “x”, i, “=”, num * i)

Leave a Reply

Discover more from Abhyas

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

Continue reading