Here is a basic example.
if x > 0:
If the input
is greater than
, we return the string
Otherwise, we return
If we want to test multiple conditions at once, we use the following general format.
if <if expression>:
elif <elif expression 0>:
<elif body 0>
elif <elif expression 1>:
<elif body 1>
Only the body for which the conditional expression is true will be evaluated. Each
expression is evaluated and considered in order, starting at the top. As soon as a true value
is found, the corresponding body is executed, and the rest of the conditional statement is skipped.
If none of the
expressions are true, then the
For more examples and explanation, refer to the section on conditional statements
Complete the following conditional statement so that the string
is assigned to the variable
if the number of nachos with cheese in
: You should not have to directly reference the variable