Python Control Structures Quiz

Questions: 16 · 10 minutes
1. What value is printed after this loop? x = 1 while x < 10: x *= 2 print(x)
8
16
32
10
2. Given age = 18, what value is assigned here? label = ""adult"" if age >= 18 else ""minor""
True
minor
18
adult
3. A function is being drafted, and one branch must temporarily contain no action while remaining syntactically valid. Which statement belongs in that branch?
continue
break
return
pass
4. What value is printed? total = 0 for i in range(5): if i == 2: continue total += i print(total)
6
The code raises an error when continue is reached.
10
8
5. Inside a loop that processes a list of temperatures, you want to skip negative values but continue processing later values. Which statement should run when a negative value is found?
pass
break
continue
return
6. How many times is print(""go"") executed? for i in range(2): for j in range(3): print(""go"")
3
5
6
2
7. Which list is produced by list(range(1, 6, 2))?
[1, 3, 5]
[1, 2, 3, 4, 5]
[1, 3, 5, 7]
[2, 4, 6]
8. What does this code print? for n in range(10, 30): if n % 7 == 0: print(n) break
14
21
14, 21, and 28
Nothing, because range() excludes 30.
9. What does this code print? x = 7 if x % 2 == 0: print(""even"") else: print(""odd"")
even
odd
7
It raises an error because % cannot be used in an if condition.
10. What does this conditional print? x = 10 if x > 5: print(""A"") elif x > 8: print(""B"") else: print(""C"")
A, because Python stops after the first matching branch
A followed by B, because both conditions are true
B, because 10 is greater than 8
C, because the conditions overlap
11. What is the output of this loop? n = 3 while n > 0: print(n, end="""") n -= 1
123
3210
321
The loop runs forever.
12. What does this code do? x = 0 if x != 0 and 10 / x > 1: print(""A"") else: print(""B"")
It raises ZeroDivisionError before choosing a branch.
It prints ""B"" because and short-circuits after x != 0 is false.
It prints ""A"" because 10 is greater than 1.
It prints nothing because the first condition is false.
13. What happens when this code runs? for n in [2, 4, 6]: if n % 2 != 0: break else: print(""All even"")
Nothing is printed because every for loop must use an explicit else condition.
The loop stops at 2 because the if condition is false.
It prints ""All even"" once for each number.
It prints ""All even"" because the loop finishes without break.
14. What does this code print? records = [] if records: print(""has records"") else: print(""empty"")
has records, because records is defined
Nothing, because a list cannot be used as a condition
empty, because an empty list is falsy
It raises a TypeError when evaluating records
15. What grade does this code print when score is 80? if score >= 90: print(""A"") elif score >= 80: print(""B"") elif score >= 70: print(""C"") else: print(""D"")
A
B
C
D
16. Which pairs are printed by this nested loop? for i in range(2): for j in range(3): if j == 1: break print(i, j)
(0, 0) and (1, 0), because break ends only the inner loop
(0, 0), (0, 2), (1, 0), and (1, 2)
(0, 0), (0, 1), (1, 0), and (1, 1)
Only (0, 0), because break ends both loops
Popular tests
Narcissistic Personality Inventory (NPI)
This self-report measure is used to assess narcissism as a personality trai…
Start Test
Yale-Brown Obsessive Compulsive Scale (Y-BOCS)
This measure is used to rapidly quantify the current severity of obsessive…
Start Test
CRAFFT Screening Test (CRAFFT 2.1)
This brief screening measure is designed to identify potential alcohol and…
Start Test
Patient Health Questionnaire-9 (PHQ-9)
This measure is commonly used to quickly screen for the presence and severi…
Start Test
Maslach Burnout Inventory (MBI)
This self-report measure is used to assess occupational burnout symptoms in…
Start Test
Adolescent Anxiety Questionnaire
This measure is designed to support a brief appraisal of anxiety symptoms a…
Start Test
Emotional Creativity Inventory (ECI)
This self-report measure assesses individual differences in the originality…
Start Test
Horne–Ostberg Morningness–Eveningness Questionnaire (MEQ)
Circadian preferences influence typical patterns of alertness and sleep tim…
Start Test
Ambivalent Sexism Inventory (ASI)
This measure is designed to assess attitudes toward women, including both o…
Start Test
Internalized Misogyny Scale (IMS)
This measure is designed to assess internalized negative beliefs and stereo…
Start Test
Perceived Stress Scale (PSS-10)
This self-report measure assesses the degree to which individuals appraise…
Start Test
Impulsive Behavior Scale (SUPPS-P)
Impulsivity is a multidimensional construct that is often assessed with bri…
Start Test
Clinical Institute Withdrawal Assessment for Alcohol, Revised (CIWA-Ar)
This rating scale is used to rapidly assess the severity of alcohol withdra…
Start Test
Positive and Negative Affect Schedule (PANAS)
This measure provides a brief self-report assessment of current or typical…
Start Test
Light Triad Scale (LTS)
This self-report measure assesses prosocial personality tendencies and orie…
Start Test
Suicidal Ideation Scale
In clinical settings, the Suicidal Ideation Scale is used to structure an i…
Start Test
Body Dysmorphic Disorder Scale (BDD-D)
This brief self-report measure is designed to screen for and quantify distr…
Start Test
Beck Anxiety Inventory (BAI)
This measure is a brief self-report inventory used to screen for anxiety sy…
Start Test
Differential Test of Perfectionism
This instrument is used to screen for perfectionism-related attitudes and t…
Start Test
Locus of Control Scale
This measure assesses generalized expectancies regarding the degree to whic…
Start Test
New Apathy Scale
This brief self-report measure is used to screen for apathy-related symptom…
Start Test
Perth Alexithymia Questionnaire (PAQ)
This measure assesses individual differences in alexithymia, including diff…
Start Test
Social Intelligence Scale
This brief self-report measure is designed to support rapid screening of in…
Start Test
Fear Test
This measure is designed to evaluate individual differences in fear-related…
Start Test
Neuroticism Level Scale
The measure is intended for brief screening of an individual’s propensity t…
Start Test
Aggressiveness Indicators Screening Questionnaire
This screening tool is designed to quickly identify behavioral indicators a…
Start Test