Help us understand the problem. What is going on with this article?

Python3 偶数判定

More than 1 year has passed since last update.

pythonで偶数、奇数判定を行う

今更感満載ですが、メモ

def is_even(num):
    if num % 2 == 0:
        return True
    else:
        return False

print(is_even(0))
print(is_even(1.5))
print(is_even(2))
print(is_even(3))

True
False
True
False

コメントで指摘いただいているように、もっと簡素化することもできますね!

def is_even(num):
    return num % 2 == 0

range関数で0から9までの数が偶数か調べる

for i in range(10):
    print('{}.is_even:{}'.format(i, is_even(i)))

0.is_even:True
1.is_even:False
2.is_even:True
3.is_even:False
4.is_even:True
5.is_even:False
6.is_even:True
7.is_even:False
8.is_even:True
9.is_even:False

fault
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした