Aim:
Write a Program for checking whether the given number is a even number or not.
Description:
Algorithm:
Input: A Number
Output: A Message
Step1: Start
Step2: Read num
Step3: Check whether the num is divisible by 2 or not. If yes, goto Step4. else, goto Step5
Step4: Display “The number is even” and goto step6
Step5: Display “The number is odd"
Step6: Stop
Program:
n=int(input("Enter a number---->"))
if n % 2 == 0:
print ("EVEN Number");
else:
print ("ODD Number");
Output:
Write a Program for checking whether the given number is a even number or not.
Description:
If a number is exactly divisible by 2(Remainder is 0) then it is said to be an Even number
otherwise, the number is said to be an Odd number. In Python, We use modulus(%) operator to find
the remainder.
Decision making is used to specify the order in which the statements are executed. We can use if…else statement to check whether the number is even or odd.
if…else statement:
This is a two-way decision making statement that decides what to do when the condition is true and what to do when the condition is false. The general form of if…else statement is as
followes:
if condition:
intended statement block for true condition
else:
intended statement block for false condition
Algorithm:
Input: A Number
Output: A Message
Step1: Start
Step2: Read num
Step3: Check whether the num is divisible by 2 or not. If yes, goto Step4. else, goto Step5
Step4: Display “The number is even” and goto step6
Step5: Display “The number is odd"
Step6: Stop
Program:
n=int(input("Enter a number---->"))
if n % 2 == 0:
print ("EVEN Number");
else:
print ("ODD Number");
Output:
Typo error in syntax of if...else statement
ReplyDeleteIts "indented"
give the space in between if and n
Delete