Python Program for checking odd even number
Topic: Odd Even Numbers
Hey Guys, today we are going see a Python Program to check whether a number is Odd or Even
Title: Python Code for Odd Even Numbers (Beginner Friendly+ Easy + Code + Output + Online Compiler)
What is this program and why we are going to use it?
This Program consists of Variables, Input Function, Conditional Statement, Comparison Operator and Arithmetic Operator.
By using variable, we are going to store values in variables in int or float format according to our use. By using input function, we are going to input values from the user. For Eg. storing the values:
a=5
b=6
here a and b are variables where 5 is assigned to a and 6 is assigned to b.
Now for input function
By using variable, we are going to store values in variables in int or float format according to our use. By using input function, we are going to input values from the user. For Eg. storing the values:
a=5
b=6
here a and b are variables where 5 is assigned to a and 6 is assigned to b.
Now for input function
a = int(input("Enter Num a:"))
So, this will ask user to input a number.
a % 2 gives us the remainder (modulus operator)
So, we know that dividing an even number by 2 gives us remainder 0.
Dividing an odd number by 2 gives us remainder 1. So, we are going to use this logic.
We are using Comparison operator "==" to check LHS = RHS which gives the output "True" or "False".
We are Using Here Conditional Statement "if...else".
Which works as it checks if statement first and if it's true it provides the output/code under if statement and if its false then it provides the output/code under else statement.
Logic:
Also we are going to use an Arithmetic Operator logic here. We know thata % 2 gives us the remainder (modulus operator)
So, we know that dividing an even number by 2 gives us remainder 0.
Dividing an odd number by 2 gives us remainder 1. So, we are going to use this logic.
We are using Comparison operator "==" to check LHS = RHS which gives the output "True" or "False".
We are Using Here Conditional Statement "if...else".
Which works as it checks if statement first and if it's true it provides the output/code under if statement and if its false then it provides the output/code under else statement.
Comments
Post a Comment