Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

question: 2 why do we use if/else statements in python? to repeat somet…

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

Explanation:

Brief Explanations
  • "To repeat something for a fixed number of times" describes a for loop (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/else statements 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 break statement, not if/else.
  • "To repeat something while a condition is true" describes a while loop.

Answer:

B. To do something if a condition is true and do something else if the condition is false