Python偶数奇数简单实现

Python下的偶数和奇数的简单实现:


# !/usr/bin/python3
# -*- coding: UTF-8 -*-

numbers = [12, 37, 5, 42, 8, 67, 32, 43, 45]
even = []
odd = []

while len(numbers) > 0:
    number = numbers.pop()
    if (number % 2 == 0):
        even.append(number)
    else:
        odd.append(number)

print("even:", even)
print ("odd:", odd)

结果:

even: [32, 8, 42, 12]
odd: [45, 43, 67, 5, 37]

你可能感兴趣的:(Python)