Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

How determine if a number is even or odd using Modulo Operator

"""
use % (modulo operator) with 2 and compare the
remainder with zero to return a Boolean.
Even numbers are divisible by 2 anddon’t have a remainder.
"""

num = int(input(">"))

def is_even_modulo(number=num):
	return number % 2 == 0

if is_even_modulo():
    print(f"{num} is an even number")
else:
    print(f"{num} is an odd number")
Comment

PREVIOUS NEXT
Code Example
Python :: Django - Knox auth setup 
Python :: pubg python 
Python :: tkinter change button foreground 
Python :: python cant remove temporary files 
Python :: size of int in python 
Python :: numeric up down python tkinter 
Python :: how to mention a role discord.py 
Python :: pip in python 
Python :: circle python programe 
Python :: torch.nan_to_num 
Python :: Concatenating objects in pandas 
Python :: django upload multiple files 
Python :: string format method python 
Python :: Palindrome in Python Using while loop for string 
Python :: django insert bulk data 
Python :: find item in list 
Python :: display pil image on kivy canvas 
Python :: python any in string 
Python :: python write a line to a file 
Python :: sort function in pandas dataframe to sort specific properties 
Python :: assert with message python 
Python :: from html to jupyter notebook 
Python :: convert list to dataset python 
Python :: how to make a stopwatch in pythoon 
Python :: pandas filter by dictionary 
Python :: export postgres database to heroku 
Python :: add a constant to a list python 
Python :: dockerize django 
Python :: how to write a function in python 
Python :: pandas print groupby 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =