0% found this document useful (0 votes)
28 views7 pages

Python Programming Activity

The document provides instructions for students to create 6 Python programs to determine if a number is odd or even using different methods like modulo operator, if/else statements, ternary operator and the pow() function. Students are asked to write the code for each program, change the font color and include a sample run. A tutorial video is provided as a reference.

Uploaded by

Rizamae Rabusa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views7 pages

Python Programming Activity

The document provides instructions for students to create 6 Python programs to determine if a number is odd or even using different methods like modulo operator, if/else statements, ternary operator and the pow() function. Students are asked to write the code for each program, change the font color and include a sample run. A tutorial video is provided as a reference.

Uploaded by

Rizamae Rabusa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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)

You might also like