feat(curriculum): Add an example of invalid syntax for an if-else block (#66399)

Co-authored-by: majestic-owl448 <26656284+majestic-owl448@users.noreply.github.com>
Co-authored-by: Aditya Singh <anshul8303858511@gmail.com>
Co-authored-by: Huyen Nguyen <25715018+huyenltnguyen@users.noreply.github.com>
This commit is contained in:
Vîzdoagă Octavio
2026-03-13 18:54:54 +02:00
committed by GitHub
parent 94517213d9
commit ceea951956
@@ -106,6 +106,18 @@ else:
print('You are not an adult yet') # You are not an adult yet
```
Note that you cannot place any statements between the `if` block and the `else` clause. The following code would raise a `SyntaxError`:
```python
age = 12
if age >= 18:
print('You are an adult')
print('Almost there!')
else: # SyntaxError: invalid syntax
print('You are not an adult yet')
```
There might be situations in which you want to account for multiple conditions. To do that, Python lets you extend your if statement with the `elif` (else if) keyword.
Here's the syntax: