Conditional Statements, Iterative Statements (Loops) 1 / 50What is the output of: for i in range(1): print(i)? 0 1 0, 1 Nothing 2 / 50How do you loop through a list and get only even-indexed elements? for x in L[::2]: for x in L[1::2]: for x in L.even(): if index % 2 == 0: 3 / 50What does ‘while False:’ with an ‘else’ block do? Runs the else block once Runs the loop once Does nothing Error 4 / 50What is the output of: x = 1; x = x + 1 if x > 0 else 0; print(x) 1 2 0 SyntaxError 5 / 50Which of these is used to define the block of code inside an ‘if’ statement? Curly braces {} Parentheses () Indentation (Spaces/Tabs) Square brackets [] 6 / 50What will happen? x = 10; while x > 5: print(x) Prints 10 and stops Prints 10, 9, 8, 7, 6 Infinite loop (x is not decreasing) Error 7 / 50What does ‘break’ do in an infinite ‘while True’ loop? Causes a crash Restarts the loop Exits the loop Nothing 8 / 50Which of the following is correct for iterating through a list ‘fruits’ backward? for x in fruits[::-1]: for x in fruits.reverse(): for x in fruits(-1): backward fruits: 9 / 50What is the result of ‘if True and False or True:’? True False Error None 10 / 50How many times will ‘Hello’ be printed? for i in range(2): for j in range(2): print(‘Hello’) 2 4 8 1 11 / 50Which of these is the ‘not’ operator in Python conditionals? ! not ~ none 12 / 50What is the result of ‘for x in range(-3):’? -3, -2, -1 0, -1, -2, -3 The loop will not execute Infinite loop 13 / 50What is the output of ‘if “” : print(“True”) else: print(“False”)’? True False None Error 14 / 50Which of the following creates a SyntaxError? if x = 5: if x == 5: while True: for i in []: 15 / 50In a ‘for’ loop, what is ‘i’ in ‘for i in range(5):’? A keyword The loop variable A function A constant 16 / 50What is the output of: for i in range(1, 10, 3): print(i, end=’ ‘)? 1 4 7 1 4 7 10 1 3 6 9 3 6 9 17 / 50What is the result of ‘while None:’? Infinite loop Runs once Never runs Error 18 / 50Which of these is used for ‘short-circuit’ evaluation in conditionals? and / or if / else for / while break / continue 19 / 50How do you check if a list ‘L’ is empty using ‘if’? if L == empty: if not L: if L.isEmpty(): if L == 0: 20 / 50Which function allows you to get the index and value at the same time in a for loop? index() enumerate() zip() range() 21 / 50What will ‘if [0]: print(‘A’)’ do? Print A (Non-empty list is True) Print nothing (0 is False) Error SyntaxError 22 / 50What is the correct way to write an infinite loop using ‘while’? while (1): while True: Both are correct while loop: 23 / 50What is the value of ‘i’ after this loop: for i in range(3): pass? 0 2 3 Undefined 24 / 50Which of these represents a ‘do-while’ loop in Python? do { … } while condition Python does not have a native 'do-while' loop while loop with 'do' keyword repeat … until 25 / 50What is the output of: for i in range(1, 1): print(i) 1 0 Nothing is printed Error 26 / 50Which keyword is used to handle situations where no condition in an ‘if-elif’ chain is met? default finally else except 27 / 50How do you loop through a dictionary to get both keys and values? for k, v in dict.keys(): for k, v in dict.items(): for k, v in dict.values(): for k, v in dict.all(): 28 / 50What is the output of: x = 5; print(‘Yes’) if x > 2 else print(‘No’) Yes No SyntaxError None 29 / 50What happens when you use ‘break’ in a nested loop? It breaks all loops It breaks the current inner loop It breaks the outer loop only It skips the next iteration 30 / 50Which of these is a valid Python ternary operator equivalent? x = (a > b) ? a : b x = a if a > b else b x = if a > b then a else b x = a > b or a : b 31 / 50What is the output of: for x in ‘Hi’: print(x)? Hi H and i on separate lines Error H i 32 / 50How do you check if a value ‘x’ is between 1 and 10 (inclusive)? if 1 <= x <= 10: if x is between 1 and 10: if x > 1 and x < 10: if x == [1…10]: 33 / 50In Python, which character is used to indicate the end of an ‘if’ or ‘for’ header? ; . : ! 34 / 50What does range(5, 0, -1) produce? 5, 4, 3, 2, 1, 0 5, 4, 3, 2, 1 0, 1, 2, 3, 4, 5 Empty sequence 35 / 50What will happen if the condition in a while loop is False from the start? The loop runs once The loop never runs The program crashes It results in an infinite loop 36 / 50Which of the following is used to check multiple conditions in one ‘if’ statement? and / or plus / minus also / either then / else 37 / 50What is the result of range(1, 10, 2)? 1, 2, 3, 4, 5, 6, 7, 8, 9 1, 3, 5, 7, 9 2, 4, 6, 8, 10 1, 10, 2 38 / 50In a nested loop, which loop completes its iterations first? The outer loop The inner loop Both complete at the same time Depends on the range 39 / 50Can an ‘else’ block be used with a ‘for’ loop? No, only with 'if' Yes, it runs if the loop completes without a 'break' Yes, it runs at every iteration Only if the loop is empty 40 / 50What is the output of: for i in range(2, 4): print(i)? 2, 3, 4 2, 3 2 3, 4 41 / 50What is the purpose of the ‘pass’ statement in a loop? To end the loop To do nothing (null operation) To restart the loop To skip to the next loop 42 / 50How do you write a ‘for’ loop that repeats 10 times? for i in 10: for i in range(10): for (i=0; i<10; i++): while range(10): 43 / 50Which loop condition would run forever? while 1 == 2: while False: while True: for i in range(0): 44 / 50What will range(5) generate? 1, 2, 3, 4, 5 0, 1, 2, 3, 4, 5 0, 1, 2, 3, 4 5, 4, 3, 2, 1 45 / 50Which keyword is used to skip the current iteration of a loop and move to the next one? next skip continue pass 46 / 50Which keyword is used to exit a loop prematurely? stop exit break end 47 / 50What is the result of ‘if 0:’ in Python? It is treated as True It is treated as False It causes a SyntaxError It returns None 48 / 50Which loop is used when you want to iterate over a sequence (like a list or string)? while for do-while foreach 49 / 50What is the correct syntax for an ‘else if’ condition in Python? elseif else if elif elsif 50 / 50Which keyword is used to start a conditional statement in Python? when if condition case Your score isThe average score is 0%