QUESTION IMAGE
Question
question: 2
why do we use if/else statements in python?
to repeat something for a fixed number of times
to do something if a condition is true and do something else if the condition is false
to break out of some block of code
to repeat something while a condition is true
Brief Explanations
- "To repeat something for a fixed number of times" describes a
forloop (e.g., iterating a fixed number of times in Python). - "To do something if a condition is true and do something else if the condition is false" matches the purpose of
if/elsestatements in Python, which execute different code blocks based on a condition's truth value. - "To break out of some block of code" is the role of the
breakstatement, notif/else. - "To repeat something while a condition is true" describes a
whileloop.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
B. To do something if a condition is true and do something else if the condition is false