Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Science, Technology, Engineering and Mathematics

Empowerment Technologies
SY 2021 – 2022

Unit 2: Introduction to Python


Lesson 8.2: Python Operators

Introduction
Hi students! Today, you will learn more
about Python specifically when it comes to
solving mathematical problems with the use of
basic operations. We learn how to use basic
operations on our grade school but now, we are
going to integrate them in creation of program
with problem solving.

Learning Objectives
After studying and completing this module with 80% to 100% mastery of the topic and get at
least 8 correct answers to the learning activity and you are also expected to:
1. Identify the different operators in Python in solving mathematical problem.
2. Create a program with the integration of Python operators.
3. Appreciate the importance of learning the use and function of different Python operators
in a program.

Pre-requisite Skills / Review


Before we begin to our lesson, let us have a short activity.

Instructions: Complete the table below by providing the information being ask.

SYMBOL USE FUNCTION

Lesson 1.1 – Python Operators

What are operators in python?

Operators in general are used to perform operations on values and variables in Python. Operators are
special symbols in Python that carry out arithmetic or logical computation. The value that the operator
operates on is called the operand.

Page 1 of 8
Science, Technology, Engineering and Mathematics
Empowerment Technologies
SY 2021 – 2022

1. Arithmetic operators: Arithmetic operators are used to perform mathematical operations like
addition, subtraction, multiplication, and division.

Example: Output:

2. Comparison operators: Comparison operators or Relational Operators are used to compare values.
It returns either True or False according to the condition.

Page 2 of 8
Science, Technology, Engineering and Mathematics
Empowerment Technologies
SY 2021 – 2022

Example: Output:

3. Logical operators: Logical operators perform Logical AND, Logical OR and Logical
NOT operations.

Example: Output:

Page 3 of 8
Science, Technology, Engineering and Mathematics
Empowerment Technologies
SY 2021 – 2022

4. Bitwise operators: Bitwise operators act on operands and performs bit by bit operation as if
they were strings of binary digits.

For example, 2 is 10 in binary and 7 is 111.

NOTE: In the table below, let x = 10 (0000 1010 in binary) and y = 4 (0000 0100 in binary)

5. Assignment operators: Assignment operators are used in Python to assign values to the
variables.

Page 4 of 8
Science, Technology, Engineering and Mathematics
Empowerment Technologies
SY 2021 – 2022

Example: Output:

6. Special Operators

➢ Identity Operators - is and is not are the identity operators both are used to check if two
values are located on the same part of the memory. Two variables that are equal does not
imply that they are identical.

Example: Output:

➢ Membership Operators - in and not in are the membership operators in Python. They are
used to test whether a value or variable is found in a sequence
(string, list, tuple, set and dictionary).

NOTE: In a dictionary we can only test for presence of key, not the value.

Page 5 of 8
Science, Technology, Engineering and Mathematics
Empowerment Technologies
SY 2021 – 2022

Example: Output:

Here, 'H' is in x but 'hello' is not present in x (remember, Python is case sensitive). Similarly, 1 is
key and 'a' is the value in dictionary y. Hence, 'a' in y returns False.

Key Concepts

➢ Python Operators - are special symbols in Python that carry out arithmetic or logical
computation. The value that the operator operates on is called the operand.
Arithmetic operators: Arithmetic operators are used to perform mathematical
operations like addition, subtraction, multiplication, and division.
Comparison operators: Comparison operators or Relational Operators are used to
compare values. It returns either True or False according to the condition.
Logical operators: Logical operators perform Logical AND, Logical
OR and Logical NOT operations.
Bitwise operators: Bitwise operators act on operands and performs bit by bit
operation as if they were strings of binary digits.
Assignment operators: Assignment operators are used in Python to assign values
to the variables.
Special Operators
▪ Identity Operators - is and is not are the identity operators both are used to
check if two values are located on the same part of the memory. Two
variables that are equal does not imply that they are identical.
▪ Membership Operators - in and not in are the membership operators in
Python. They are used to test whether a value or variable is found in a
sequence (string, list, tuple, set and dictionary).

Page 6 of 8
Science, Technology, Engineering and Mathematics
Empowerment Technologies
SY 2021 – 2022

Learning Activity

PERFOMANCE TASK #2_Program

This performance task is a group activity, so everyone expected to help and contribute on
the task. Learning about the different operators in Python, your task is to create a program
that will solve the following mathematical problem with the integration of different Python
topics that we have discussed.

1. Pretend you have a store, your customer bought 5 items in your store. Create a program
that will let you input prices of the items bought in your store, it will also display the total
amount to pay, and the cash paid by the customer. This program will also let you compute
the change of your costumer.

2. You already viewed your grades for this semester; however, you can only view your grades
per subject. Create a program that will let you input your grades in every subject and can
also get your final average using Python Operators.

Study Questions/Forum:

In your own opinion, are Python operators useful in creating a program? Why and why
not?

Tutorial Videos

Here are some YouTube videos that can help you to with this topic.

References

• Book:
o Python Notes for Professionals – Free Python Programming Book (goalkicker.com)
o A Practical Introduction to Python Programming - Brian Heinold
Department of Mathematics and Computer Science Mount St. Mary’s University
• Online Sources
o https://www.w3schools.com/python/python_intro.asp
o https://www.programiz.com/python-programming/first-program
o https://www.geeksforgeeks.org/python-language-introduction/
o https://www.educba.com/python-literals/
o https://www.codespeedy.com/literals-in-python-with-examples/

Page 7 of 8
Science, Technology, Engineering and Mathematics
Empowerment Technologies
SY 2021 – 2022

Enrichment Activity

Create and solve the following using Python Operators.

1. Subtract your year of birth to the current year.


2. Convert your weight (kg) to pounds (lbs) (2.2 lbs= 1kg)
3. Add the age of your mother and father.
4. Split your monthly budget to the number of family members.

III. Given the value below, using membership operators to solve the following problems whether
TRUE or FALSE.
x = ‘Empowerment Technologies number one!’
1. EMPTECH is in x.
2. Number 1 is not in x

Page 8 of 8

You might also like