: Write a Python function named "is_even" that takes an integer as input and returns True if the number is even, and False otherwise
时间: 2024-03-10 22:44:55 浏览: 118
判断输入的是否是正数
Sure! Here's the Python code for the `is_even` function that takes an integer as input and returns `True` if the number is even, and `False` otherwise:
```python
def is_even(num):
if num % 2 == 0:
return True
else:
return False
```
You can call this function by passing an integer as an argument like this:
```python
print(is_even(4)) # Output: True
print(is_even(5)) # Output: False
```
In the first call to the function, the input `4` is an even number, so the function returns `True`. In the second call to the function, the input `5` is an odd number, so the function returns `False`.
阅读全文