INSTRUCTIONS: (ODD/EVEN PROBLEM)
1. Create six different versions of Python Program Solutions.
a. Division by 2 - ONE WAY IF STATEMENT
b. Division by 2 - TWO WAY IF STATEMENT
c. Division by 2 - TERNARY OPERATOR
d. pow() function - ONE WAY IF STATEMENT
e. pow() function -- TWO WAY IF STATEMENT
f. pow() function - TERNARY OPERATOR
2. You can refer to this TUTORIAL VIDEO for your reference.
https://www.youtube.com/watch?v=s3tr8yfZb7Y&t=636s
PRACTICAL EXERCISE 1 : ODD/EVEN (Division by 2 - ONE WAY)
Program Code (Copy your Code and change font color to Red or Blue)
num= int (input("Enter Number: "))
if num %2 == 0:
print("{0} is an Even number".format(num))
Sample Run (Print Screen – using PYCHARM or ONLINEGDB)
PRACTICAL EXERCISE 2 : ODD/EVEN (Dividing by 2 - TWO WAY)
Program Code (Copy your Code and change font color to Red or Blue)
num= int (input("Enter Number: "))
if num %2 == 0:
print("{0} is an Even number".format(num))
else:
print("{0} is an Odd number".format(num))
Sample Run (Print Screen – using PYCHARM or ONLINEGDB)
PRACTICAL EXERCISE 3 : ODD/EVEN (Division by 2 - TERNARY)
Program Code (Copy your Code and change font color to Red or Blue)
num= int (input("Enter Number: "))
print()
print("{0} is an Even number".format(num)) if (num %2 == 0) else print("{0} is an Odd
number".format(num))
print("End of Program")
Sample Run (Print Screen – using PYCHARM or ONLINEGDB)
PRACTICAL EXERCISE 4 : ODD/EVEN (ONE-WAY IF STATEMENT)
( using pow() function, -1 as base and num as power )
Program Code (Copy your Code and change font color to Red or Blue)
num= int (input("Enter Number: "))
print()
if pow(-1, num) == 1 : print("The Number {0} is Even".format(num))
if pow(-1, num) == -1 : print("The Number {0} is an Odd Number".format(num))
Sample Run (Print Screen – using PYCHARM or ONLINEGDB)
PRACTICAL EXERCISE 5 : ODD/EVEN (TWO-WAY IF STATEMENT)
( using pow() function, -1 as base and num as power )
Program Code (Copy your Code and change font color to Red or Blue)
num = int(input("Enter Number: "))
print()
if pow(-1, num) == 1 : print("The Number {0} is Even".format(num))
else:
print("The Number {0} is Odd".format(num))
Sample Run (Print Screen – using PYCHARM or ONLINEGDB)
PRACTICAL EXERCISE 6 : ODD/EVEN (TERNARY OPERATOR)
( using pow() function, -1 as base and num as power )
Program Code (Copy your Code and change font color to Red or Blue)
num = int(input("Enter Number: "))
print()
print("{0} is an Even number".format(num)) if pow(-1, num) == 1 else print("{0} is an Odd
number".format(num))
Sample Run (Print Screen – using PYCHARM or ONLINEGDB)