1 What is the purpose of the elif statement in Python? A To check another condition if the previous conditions are false B To repeat a block of code C To define a function D To import a library
2 Which tool helps to run a Python program step by step to find errors? A Compiler B Debugger C Editor D Interpreter
3 What does the range(5) function generate in a for loop? A Numbers from 1 to 5 B Numbers from 0 to 4 C Numbers from 0 to 5 D Numbers from 1 to 4
4 What is the purpose of the else clause with a for loop in Python? A It runs before the loop starts B It runs after the loop finishes normally C It skips the loop D It stops the loop
5 What happens if the condition of a while loop always remains true? A The loop runs once and stops. B The loop never runs. C The loop runs forever (infinite loop). D The loop gives a syntax error.
6 if-else اسٹیٹمنٹ میں else بلاک کیا کرتا ہے؟ A Runs when the if condition is true B Runs when the if condition is false C Runs before the if condition D Stops the program
7 What is the output of the following code? for i in range(3): print(i) A 0 1 2 B 1 2 3 C 0 1 2 3 D 1 2
8 What does the statement import random do? A Imports the random module for use B Creates a random number C Deletes the random module D Prints a random number
9 What does an if statement inside another if statement create? A A loop B A nested condition C A list D A library
10 What is the purpose of the else clause in an if-else statement? A It executes when the if condition is false B It executes when the if condition is true C It is used to test another condition D It stops the program
11 What does the continue statement do inside a loop? A It stops the loop completely B It skips the rest of the current iteration and goes to the next C It restarts the loop from the beginning D It exits the program
12 What happens if the condition of a while loop never becomes false? A The loop stops automatically B The loop runs forever C The loop is skipped D The program gives a syntax error
13 How many times does the inner loop run for each single run of the outer loop in a nested loop? A Zero times B One time C As many times as its own condition allows D Only when the outer loop ends
14 What is the purpose of debugging in programming? A To write code faster B To find and fix errors C To make the program run slower D To add more features
15 What is a loop inside another loop called? A Nested loop B Hidden loop C Simple loop D Closed loop
16 What does the following code do?\nimport random\nprint(random.randint(1, 10)) A Prints a random integer between 1 and 10 B Prints numbers from 1 to 10 C Prints 1 and 10 D Causes an error
17 Why do we use libraries in Python? A To write all code from scratch B To reuse ready-made code for common tasks C To make the program slower D To remove all errors automatically
18 What is a nested loop? A A loop inside another loop B A loop with no condition C A loop that runs only once D A loop that uses if statement
19 What is the purpose of the import statement in Python? A To include a library or module B To define a variable C To create a loop D To print output
20 if-else ڈھانچے میں else بلاک کیا کرتا ہے؟ A یہ اس وقت چلتا ہے جب if کی شرط درست ہو B یہ اس وقت چلتا ہے جب if کی شرط غلط ہو C یہ کوئی اور شرط جانچتا ہے D یہ پروگرام روک دیتا ہے
21 In Python, which part of an if-else statement is executed when the condition is false? A The if block B The else block C The elif block D No block runs
22 What does my_list.append(5) do? A Removes 5 from the list B Adds 5 at the end of the list C Changes 5 to 0 D Sorts the list
23 What is debugging? A Writing code B Finding and fixing errors C Running the program D Saving the program
24 What is the main purpose of testing a program? A To make the program run faster B To find and fix errors C To add more features D To change the programming language
25 How is a list created in Python? A Using square brackets [] B Using curly brackets {} C Using round brackets () D Using angle brackets <>