PREVIOUS CHAPTER QUESTION BANK CLICK BELOW
[NOTE: Kindly cross check answers once from other source also, Quantity and Quality of answers also kindly check before use, specially 5 marks answers are not sufficient kindly add from your side, this gives just quick review]
50 MCQ questions with answers
The flow of control in Python is managed using:
A) Comments
B) Control structures
C) Functions
D) Variables
Answer: BIn Python, which construct handles decision making?
A) for loop
B) if statement
C) continue statement
D) break statement
Answer: BThe simplest flow control structure is:
A) Selection
B) Repetition
C) Sequence
D) Nested loop
Answer: CWhich keyword is used for a single alternative selection?
A) elif
B) if
C) while
D) for
Answer: BWhat does indentation define in Python?
A) Type of variable
B) Block of code
C) Output format
D) Error type
Answer: BSelect the statement that is NOT a loop in Python.
A) while
B) for
C) if
D) continue
Answer: CThe operator used to compare values in an if condition is:
A) +
B) ==
C) =
D) //
Answer: BWhat is the output of:
pythonif 3 < 5: print("Yes") else: print("No")
A) Yes
B) No
C) True
D) Error
Answer: A
Which keyword allows you to check multiple conditions?
A) if
B) elif
C) while
D) continue
Answer: BThe 'else' block is executed when:
A) The 'if' block is true
B) The 'if' block is false
C) Always
D) Never
Answer: BWhich Python statement is used for repetition?
A) if
B) while
C) break
D) elif
Answer: BWhat will
for i in range(3): print(i)print?
A) 1 2 3
B) 0 1 2
C) 0 1 2 3
D) 3 2 1
Answer: BHow many times will the body of a while loop
while count <= 5:run if count is initialized as 1?
A) 4
B) 5
C) 6
D) infinite
Answer: BWhich function is used to generate a sequence in Python for loops?
A) list()
B) range()
C) sequence()
D) tuple()
Answer: BWhat does the 'break' statement do in a loop?
A) Skips one iteration
B) Terminates the loop
C) Continues next iteration
D) Throws error
Answer: BWhat does the 'continue' statement do?
A) Exits the program
B) Skips rest of loop block for current iteration
C) Terminates while loop
D) Runs next if block
Answer: BFor nested loops, the inner loop runs:
A) Before the outer loop
B) After the outer loop
C) For each iteration of outer loop
D) Only once
Answer: CWhat is the output type of input() function?
A) int
B) float
C) string
D) bool
Answer: CWhat will be the output of:
pythonage = 17 if age >= 18: print("Adult") else: print("Minor")
A) Adult
B) Minor
C) Error
D) None
Answer: B
Which symbol is used for equal comparison?
A) =
B) ==
C) =>
D) <=
Answer: BWhat is the key purpose of range(start, stop, step)?
A) Sorting values
B) Generating sequences
C) Repeating code
D) Comparing values
Answer: BWhat will
range(1, 5, 2)generate?
A)
B)
C)
D)
Answer: BWhat does 'elif' stand for?
A) Else If
B) Else Loop
C) Element If
D) Error If
Answer: AA properly indented block avoids ___ errors.
A) Syntax
B) Logical
C) Type
D) Output
Answer: AWhich is not a valid loop type in Python?
A) for
B) while
C) do-while
D) nested
Answer: CWhat value returns the termination of a while loop with condition
count <= 10if count starts at 1 and increases by 2 each time?
A) 4 times
B) 5 times
C) 10 times
D) 6 times
Answer: DChoose the false statement:
A) 'break' immediately exits loop block
B) 'continue' ends entire program
C) 'while' can cause infinite loops
D) 'for' uses sequence
Answer: BWhat is a nested loop?
A) Loop inside a variable
B) Loop inside a loop
C) Loop inside a function
D) Loop inside an if
Answer: BWhat is the result of:
pythonfor i in range(2, 6): print(i)
A) 2, 3, 4, 5
B) 2, 3, 4, 5, 6
C) 1, 2, 3, 4, 5
D) 6, 7, 8
Answer: A
The result when 0 is given for step in range():
A) Error
B)
C) Infinite loop
D) [0, 1, ...]
Answer: AWhich is default start in range(stop)?
A) 1
B) 0
C) stop
D) -1
Answer: BWhich output is generated by range(10, 20, 2)?
A)
B)
C)
D)kecs105.pdf
Answer: AWhich control allows skipping one iteration in a loop?
A) break
B) continue
C) skip
D) pass
Answer: BWhat will be printed:
pythonfor ch in "ABC": print(ch)
A) ABC
B) A, B, C
C) Error
D) ch
Answer: B
Which function converts string input to integer?
A) str()
B) int()
C) float()
D) input()
Answer: BThe outcome when 'break' is used in while True loop:
A) Infinite loop
B) Loop terminates immediately
C) Loop never starts
D) Error
Answer: BIn a loop, what is an 'iteration'?
A) One execution of loop body
B) Start of program
C) Printing output
D) Variable assignment
Answer: AWhich loop is ideal when number of iterations is known?
A) for
B) while
C) nested
D) infinite
Answer: AHow does Python treat indentation?
A) Ignores it
B) Requires it strictly
C) Replaces with braces
D) Causes runtime error
Answer: BWhat is the output of:
pythoni = 0 while i < 3: print(i) i += 1
A) 1 2 3
B) 0 1 2
C) 0 1 2 3
D) Error
Answer: B
What does the expression
if x != y:mean?
A) x equals y
B) x not equals y
C) x less than y
D) x greater than y
Answer: BLoop that may run infinitely unless condition changes:
A) for loop
B) while loop
C) continue
D) pass
Answer: BWhich can be used to generate decreasing sequence?
A) range(10, 0, -1)
B) range(0, 10, -1)
C) range(10, -1, 1)
D) range(1, 10, -2)
Answer: AThe 'pass' statement is used for:
A) Skipping code block
B) Exiting loop
C) Continuing iteration
D) Placeholder for future code
Answer: DThe 'else' with a loop executes when:
A) Loop ends normally
B) Loop is broken
C) Loop is infinite
D) Loop contains continue
Answer: AWhat data type does input() return?
A) int
B) float
C) str
D) bool
Answer: CWhich command prints numbers from 1 to 5?
A) for i in range(1,6): print(i)
B) for i in range(0,5): print(i)
C) for i in range(1,5): print(i)
D) for i in range(1,7): print(i)
Answer: AIn nested loops, exit of inner loop causes:
A) Both loops exit
B) Outer loop continues
C) Program ends
D) Next iteration starts
Answer: BWhich is NOT a Python control structure?
A) Sequence
B) Selection
C) Iteration
D) Expansion
Answer: DWhich of these can NOT be used for testing equality in Python?
A) ==
B) is
C) =
D) !=
Answer: C
1 mark questions with answers
-
What is the simplest flow control structure in Python?
Answer: Sequence -
Which keyword is used for decision making in Python?
Answer: if -
What term describes code executed line by line from start to finish?
Answer: Sequence -
Which statement is used for repetition in Python?
Answer: while -
Which function generates a sequence of numbers in Python?
Answer: range() -
What keyword is used for multiple conditions after if?
Answer: elif -
Python uses _______ to define a block of code.
Answer: Indentation -
Which operator is used for equality comparison in if condition?
Answer: == -
What statement is used to exit a loop before its natural end?
Answer: break -
Which statement skips the rest of a loop body for current iteration?
Answer: continue -
What type does input() function return?
Answer: String (str) -
What is a nested loop?
Answer: A loop inside another loop. -
Which control structure allows selection between alternate paths?
Answer: Selection (if-else) -
What do you call the repeated execution of program statements?
Answer: Iteration or Looping -
Which key word is used to leave a code block as a placeholder?
Answer: pass -
What is the output of range(3)?
Answer: 0, 1, 2 -
Which statement is true for while loops?
Answer: Condition checked before iteration -
What happens if loop condition is always true?
Answer: Infinite loop -
Which structure handles branching in Python?
Answer: Selection (if-else) -
What block executes if all if/elif conditions fail?
Answer: else
2 mark questions with answers
What is the role of sequence in Python programs?
Answer:
Sequence ensures statements are executed one after another in the order they appear, maintaining a logical flow.Define selection in flow of control with an example.
Answer:
Selection allows choosing among alternative paths; e.g.,if age >= 18: print("Adult") else: print("Minor").Explain the while loop structure in Python.
Answer:
A while loop repeats a block as long as its condition evaluates to True. Example:while x < 5: print(x); x += 1.What does the ‘break’ statement do inside loops?
Answer:
It instantly exits the current loop, skipping all remaining iterations of the loop body.How is indentation used in Python for flow of control?
Answer:
Indentation marks the start and end of code blocks, especially within loops and selection statements.Describe the use of ‘elif’ in decision making.
Answer:
‘elif’ checks multiple conditions after an ‘if’ and before ‘else’, allowing complex branching.When does the else block execute after an if statement?
Answer:
It runs if the if and any preceding elif conditions are all False.Why is range() commonly used in for loops?
Answer:
range() generates sequences of numbers, enabling controlled iteration in for loops.What is a nested loop? Give an example.
Answer:
Loop inside another loop, e.g.,
pythonfor i in range(2): for j in range(2): print(i, j)
What is the result of
for i in range(2, 8, 2): print(i)?
Answer:
Prints 2, 4, 6; range produces numbers from 2 up to but not including 8, step 2.What are advantages of structured flow control in programming?
Answer:
It improves code clarity, logic, debugging, and maintains manageable program complexity.How can you skip the rest of a loop’s body for the current iteration?
Answer:
Use the continue statement to move to the next loop iteration immediately.How does Python prevent ambiguity with indentation?
Answer:
Mandatory indentation visually separates blocks, preventing logical and syntax errors.Give the output of:
pythonif 'A' > 'B': print("First") else: print("Second")
Answer:
Second
What is the effect of an infinite loop in Python?
Answer:
It repeatedly executes the loop body, potentially freezing the program unless forcibly stopped.Differentiate between ‘for’ and ‘while’ loops with examples.
Answer:
‘for’ loop: known iterations, e.g.for i in range(3). ‘while’ loop: unknown, condition-based, e.g.,while x > 0.How does the pass statement function in Python programs?
Answer:
Acts as a placeholder where a statement is required syntactically but no action is needed.What happens if break is applied within a nested loop’s inner loop?
Answer:
Only the inner loop exits; the outer loop continues its next iteration.Give the output of:
pythoncount = 1 while count < 4: print(count) count += 1
Answer:
1 2 3
How are decision structures useful in real-life applications?
Answer:
They help make choices: e.g., ATM checking balance before withdrawal, login system verifying credentials.
3 mark questions with answers
Explain with code how an if-elif-else ladder works in Python.
Answer:
The ladder checks multiple conditions in sequence:
pythonx = 15 if x < 10: print("Less than 10") elif x == 15: print("Equals 15") else: print("Greater than 10")
This prints "Equals 15".
Write a Python program to print numbers 1 to 10 using a while loop.
Answer:
pythoni = 1 while i <= 10: print(i) i += 1
How does indentation influence program execution in Python?
Answer:
Indentation defines code blocks for statements like if, for, while. Misplaced indentation causes syntax errors and changes program logic.Illustrate the use of ‘break’ and ‘continue’ with examples.
Answer:
‘break’ exits loop; ‘continue’ skips to next iteration.
pythonfor i in range(5): if i == 3: break print(i) # prints 0,1,2 for j in range(5): if j == 3: continue print(j) # skips 3
Describe the structure of a for loop in Python.
Answer:for variable in sequence:
Executes the block for each value in the sequence.Differentiate between sequence, selection, and iteration with suitable examples.
Answer:
Sequence: statements in order;
Selection: if-else to choose path;
Iteration: for/while loops for repetition.Write a nested loop to print a 3x3 matrix with numbers 1-9.
Answer:
pythonnum = 1 for i in range(3): for j in range(3): print(num, end=' ') num += 1 print()
How can range(start, stop, step) be used in for loops?
Answer:
Generates sequences; example:for i in range(2, 10, 2): print(i)prints 2 4 6 8.Explain what happens when the while loop’s condition is never false.
Answer:
It creates an infinite loop, running endlessly unless interrupted by 'break' or an external stop.Describe three logical errors that may arise using control structures.
Answer:
Infinite loops due to incorrect condition;
Wrong branch chosen in if-else due to misused operators;
Skipping loop body due to off-by-one errors.Write a code to sum numbers from 1 to 100 using a for loop.
Answer:
pythons = 0 for i in range(1, 101): s += i print(s)
State how ‘else’ behaves with a loop in Python.
Answer:
‘else’ with a loop executes only if the loop was not exited by a ‘break’ statement.How does the ‘pass’ statement help in flow of control?
Answer:
It’s a placeholder when no action is needed, keeps block syntactically correct, especially during development.Give an example where selection is essential in a real-world Python program.
Answer:
ATM withdrawal: checking if balance is sufficient—if yes, dispense cash; else, show error.Write a program using nested loops to display a right-angled triangle of stars.
Answer:
pythonfor i in range(1, 6): for j in range(i): print("*", end="") print()
Explain how ‘break’ works in both for and while loops with example.
Answer:
For loop:
pythonfor i in range(10): if i == 4: break print(i)
While loop:
pythonx = 0 while x < 10: if x == 4: break print(x) x += 1
Illustrate flow of control for a number-guessing game (1-10) in Python.
Answer:
pythonimport random num = random.randint(1,10) guess = int(input("Guess: ")) if guess == num: print("Correct!") elif guess < num: print("Too low") else: print("Too high")
Discuss possible consequences of missing indentation in a program with control structures.
Answer:
Leads to syntax errors or unintended grouping of code, causing program malfunction or unpredictable results.What are nested loops used for? Give a practical example.
Answer:
Used to work with multi-dimensional data, e.g., printing tables, matrices, game grids.Show how to use for loop and if statement together to print even numbers from 1 to 20.
Answer:
pythonfor i in range(1, 21): if i % 2 == 0: print(i)
5 mark questions with answers
Explain different types of control structures in Python with examples.
Answer:
Python supports three primary control structures — sequence, selection, and iteration.
Sequence: Code runs line by line in the order written, e.g.:
pythona = 5 b = 7 print(a + b)Selection: Decisions through if-else or if-elif-else:
pythonage = int(input("Enter age: ")) if age >= 18: print("Eligible") else: print("Not eligible")Iteration: Repetition using for and while loops:
pythonfor i in range(5): print(i) count = 0 while count < 5: print(count) count += 1
These structures allow flexible program design and handle various logical situations.
Discuss with examples the difference between break and continue statements in Python loops.
Answer:
Thebreakstatement ends the nearest enclosing loop instantly, whilecontinueskips the current iteration and resumes the next.
break example:
pythonfor i in range(10): if i == 5: break print(i) # Prints 0 to 4continue example:
pythonfor i in range(6): if i == 3: continue print(i) # Prints 0,1,2,4,5 (skips 3)
Use break to abort loops early and continue to skip certain cases but continue looping.
Describe the working of if...elif...else with a program to check if a number is positive, negative, or zero.
Answer:
The if...elif...else chain in Python allows checking multiple conditions sequentially:
pythonnum = int(input("Enter a value: ")) if num > 0: print("Positive") elif num < 0: print("Negative") else: print("Zero")
This program gets a number from the user, checks its sign, and prints the result. Only one block executes, and else is the default when no condition matches.
Write a program to input two numbers and perform addition, subtraction, multiplication, and division as per user’s choice. Handle division by zero.
Answer:
pythona = float(input("Enter first number: ")) b = float(input("Enter second number: ")) op = input("Choose operator (+, -, *, /): ") if op == '+': print("Sum =", a + b) elif op == '-': print("Difference =", a - b) elif op == '*': print("Product =", a * b) elif op == '/': if b == 0: print("Error: Division by zero") else: print("Quotient =", a / b) else: print("Invalid operator")
The program performs operations as per user’s choice and handles division by zero without crashing.
Explain the structure and use of for and while loops in Python. Show how to print even numbers from 1 to 20 using both loops.
Answer:
For loop:
pythonfor i in range(2, 21, 2): print(i)Starts at 2, increments by 2, prints all even numbers till 20.
While loop:
pythoni = 2 while i <= 20: print(i) i += 2
Both loops achieve the same result, but for is used when the number of iterations is known, while while handles condition-based repetition.
What is indentation in Python? Explain its role and consequences of improper indentation with examples.
Answer:
Indentation is mandatory in Python and groups statements into blocks.
Proper example:
pythonif a > 0: print("Positive") print("Number tested") else: print("Non-positive")
Improper indentation gives:
pythonif a > 0: print("Positive") print("Number tested") else: print("Non-positive")
which raises an IndentationError. Correct indentation is critical for flow control and prevents logic/syntax errors.
Write a Python program that prints a pattern as follows for n = 5:
text1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Explain how control structures create this pattern.
Answer:
pythonn = 5 for i in range(1, n+1): for j in range(1, i+1): print(j, end=' ') print()
Outer loop (1 to n): controls rows; inner loop (1 to i): prints numbers on each row. Line break after each row. Nested loops enable construction of the pattern row by row.
Define an infinite loop with an example. How can you prevent a loop from becoming infinite?
Answer:
An infinite loop keeps executing as its condition never becomes False.
Example:
pythonwhile True: print("This will run forever.")
To prevent it: ensure the loop condition will eventually fail, or use break when a specific condition is met:
pythonwhile True: x = int(input("Enter number: ")) if x == 0: break
Describe nested loops and provide a program to print a multiplication table (1 to 5).
Answer:
Nested loops are loops inside other loops.
Program:
pythonfor i in range(1, 6): for j in range(1, 11): print(f"{i} x {j} = {i*j}") print()
Outer loop for each table (1-5), inner loop for multiples (1-10). Prints tables one after another.
Write a program to input the percentage of marks and display the grade as per criteria: Above 90 = A, 80 to 90 = B, 70 to 80 = C, 60 to 70 = D, Below 60 = E. Explain the use of control structures used.
Answer:
pythonperc = float(input("Enter percentage: ")) if perc > 90: print("Grade A") elif perc >= 80: print("Grade B") elif perc >= 70: print("Grade C") elif perc >= 60: print("Grade D") else: print("Grade E")
.png)
Comments
Post a Comment