Differences
This shows you the differences between two versions of the page.
Next revisionBoth sides next revision | |||
184_notes:if [2022/04/20 15:23] – created woodsna1 | 184_notes:if [2022/04/20 15:24] – woodsna1 | ||
---|---|---|---|
Line 7: | Line 7: | ||
quotient = numerator/ | quotient = numerator/ | ||
</ | </ | ||
- | Everything that follows the word " | + | Everything that follows the word " |
+ | |||
+ | ===== Else Clauses ===== | ||
+ | |||
+ | We often want the computer to do something else if the conditional evaluates to False. We can accomplish this with an " | ||
< | < | ||
if denominator != 0: | if denominator != 0: | ||
Line 15: | Line 19: | ||
</ | </ | ||
In this code, the quotient will be set to some high number when the denominator is 0, instead of trying to calculate the true quotient. Code contained in else clauses only executes when the if statement' | In this code, the quotient will be set to some high number when the denominator is 0, instead of trying to calculate the true quotient. Code contained in else clauses only executes when the if statement' | ||
+ | |||
+ | ===== Nesting If Statements ===== | ||
Similarly to loops, we can use nested if statements: | Similarly to loops, we can use nested if statements: |