mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
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:
+12
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user