Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How determine if a number is even or odd using Recursive Inner Function

"""
We can refactor the function to use a recursive inner function that calls itself to
subtract 2 from the starting number until the number is less than 2, and then use
% (modulo operator) with 2 and compare the remainder with zero to return a
Boolean. Even numbers are divisible by 2 and don’t have a remainder.
"""

def is_even_recursive(number):
	def check(num):
		if (num < 2):
			return num % 2 == 0
		return check(num - 2)
	
    if check(number):
		return True
	return False
    
Comment

PREVIOUS NEXT
Code Example
Python :: how to pass on all the arguments to internal function in python 
Python :: split dataset folders in train test valid using python 
Python :: find downold dir in python 
Python :: Python check if caps lock is pressed 
Python :: Print feature importance per feature 
Python :: python check vpn ip address 
Python :: Python Tkinter Menu Widget Syntax 
Python :: calculate iou of two rectangles 
Python :: difference() Function of sets in python 
Python :: Shallow copy in python and adding another array to list 
Python :: Change the transparency of histogram 
Python :: Location of INSTALLED_APP and MIDDLEWARE 
Python :: logged_passengers 
Python :: python Pandas - Analyzing DataFrames 
Python :: print anything in python 
Python :: python rest api interview questions 
Python :: assert isinstance python 
Python :: how to write def 
Python :: pylance not reading django 
Python :: python basic programs area caluclation 
Python :: Matrix Transpose using Nested List Comprehension 
Python :: django queryset or operator 
Python :: preventing players to make entry in the same block in a python tic tac toe game 
Python :: una esfera solida de radio 40 cm tiene una carga positiva 
Python :: The module in NAME could not be imported: django.contrib.user_auth.password_validation.UserAttributeSimilarityValidator. Check your AUTH_PASSWORD_VALI 
Python :: can 2020 get any worse 
Python :: multivariable traces f(x, y) = sin(x)cos(y) 
Python :: add 10 min to current time django 
Python :: How to create a rect with an image 
Python :: python deque deep copy 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =