Contibuted by: BraydonKains
This is the way everyone in the Programmer Nullposting group says is the best.
def isEven(x):
return x % 2 == 0
Contributed by: Angus L'Herrou
What, you aren't using generators? Are you even a python programmer?
def is_even(x):
return [even for n, even in zip(range(abs(x)+1), gen_even())][abs(x)]
def gen_even():
even = True
while True:
yield even
even = not even
Contributed by Alexander Wong
Stringify and regex all of the things?
import re
def is_even(x):
return bool(re.search(r'[02468]$', str(x)))
Contributed by: Tanner Collin
Uses the isEven API free tier.
This tier only supports numbers 0 - 999,999. Upgrade to the Premium or Enterprise tier for more numbers.
import requests
ISEVEN_API = 'https://api.isevenapi.xyz/api/iseven/'
def isEven(x):
try:
url = ISEVEN_API + str(x)
r = requests.get(url, timeout=5)
r.raise_for_status()
return r.json()['iseven']
except BaseException as e:
print('isEven API problem:', e)
return None