Skip to content

Commit 1c6ac22

Browse files
donaldharveyDonald Harvey
authored andcommitted
elif more detail and example: fixes #248
1 parent 96d537a commit 1c6ac22

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

en/python_introduction/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,30 @@ and executed:
525525
$ python3 python_intro.py
526526
Hey Sonja!
527527

528-
See what happened there?
528+
See what happened there? `elif` lets you add extra tests that run if the previous tests fail.
529+
530+
You can add as many `elif` statements as you like after your initial `if` statement. For example:
531+
532+
```python
533+
volume = 57
534+
if volume < 20:
535+
print("It's kinda quiet.")
536+
elif 20 <= volume < 40:
537+
print("It's nice for background music")
538+
elif 40 <= volume < 60:
539+
print("Perfect, I can hear all the details")
540+
elif 60 <= volume < 80:
541+
print("Nice for parties")
542+
elif 80 <= volume < 100:
543+
print("A bit loud!")
544+
else:
545+
print("My ears are hurting! :(")
546+
```
547+
548+
Python runs through each test in sequence and prints:
549+
550+
$ python3 python_intro.py
551+
Perfect, I can hear all the details
529552

530553
### Summary
531554

0 commit comments

Comments
 (0)