Add is_even and is_odd snippets
This commit is contained in:
18
snippets/is_even.md
Normal file
18
snippets/is_even.md
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
title: is_even
|
||||
tags: math,beginner
|
||||
---
|
||||
|
||||
Returns `True` if the given number is even, `False` otherwise.
|
||||
|
||||
Checks whether a number is odd or even using the modulo (`%`) operator.
|
||||
Returns `True` if the number is even, `False` if the number is odd.
|
||||
|
||||
```py
|
||||
def is_even(num):
|
||||
return num % 2 == 0
|
||||
```
|
||||
|
||||
```py
|
||||
is_even(3) # False
|
||||
```
|
||||
18
snippets/is_odd.md
Normal file
18
snippets/is_odd.md
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
title: is_odd
|
||||
tags: math,beginner
|
||||
---
|
||||
|
||||
Returns `True` if the given number is odd, `False` otherwise.
|
||||
|
||||
Checks whether a number is even or odd using the modulo (`%`) operator.
|
||||
Returns `True` if the number is odd, `False` if the number is even.
|
||||
|
||||
```py
|
||||
def is_odd(num):
|
||||
return num % 2 == `0`
|
||||
```
|
||||
|
||||
```py
|
||||
is_odd(3) # True
|
||||
```
|
||||
Reference in New Issue
Block a user