0% found this document useful (0 votes)
38 views20 pages

Lesson 2

The document outlines the basics of Python programming, focusing on variables, data types, and operators. It explains how to create variables, the rules for naming them, and the different types of operators available in Python, including arithmetic, assignment, relational, and logical operators. Additionally, it includes practice exercises for applying arithmetic operators and determining relationships between values.
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)
38 views20 pages

Lesson 2

The document outlines the basics of Python programming, focusing on variables, data types, and operators. It explains how to create variables, the rules for naming them, and the different types of operators available in Python, including arithmetic, assignment, relational, and logical operators. Additionally, it includes practice exercises for applying arithmetic operators and determining relationships between values.
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
You are on page 1/ 20

COMPUTER

PROGRAMMING
INTENDED LEARNING
OUTCOMES

The student are able to use different operators in solving


mathematical and computer problem
REVIEW

• Python Variables

• Variables
o Variables are containers for storing data values.
REVIEW

• Creating Variables
• A variable is created the moment you first assign a value to it.
• Example
• x=5
y = "John"
print(x)
print(y)

• Variables do not need to be declared with any particular type,


and can even change type after they have been set.
REVIEW

• Casting
o If you want to specify the data type of a variable, this can be done with casting.

• Example
• x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
REVIEW

• Variable Names (IDENTIFIER)


• A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume). Rules for
Python variables:

o A variable name must start with a letter or the underscore character


o A variable name cannot start with a number
o A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9,
and _ )
REVIEW

• DATA TYPES
- STR (TEXT)
- INT (WHOLE NUMBER)
- FLOAT (DECIMAL NUMBERS)
- BOOLEAN (TRUE OR FALSE)
Python Operators
• Is a graphic visual representations of information, data, or
knowledge intended to present information quickly and clearly
• Operators are used to perform operations on
variables and values.
o In the example below, we use the + operator to add together two
values:

o Example
o print(10 + 5)
• Python divides the operators in the following
groups:

o Arithmetic operators
o Assignment operators
o Comparison operators
o Logical operators
o Identity operators
o Membership operators
o Bitwise operators
Python Arithmetic Operators

Operator Name Example


+ Addition x+y
- Subtraction x-y
* Multiplication x*y
/ Division x/y
% Modulus x%y
** Exponentiation x ** y
Python Arithmetic Operators
LETS EVALUATE EACH LINE

• a = 21
• b = 10
• c=0
• c=a+b
• print "Line 1 - Value of c is ", c
• c=a-b
• print "Line 2 - Value of c is ", c
• c=a*b
• print "Line 3 - Value of c is ", c
• c=a/b
• print "Line 4 - Value of c is ", c
• c=a%b
• print "Line 5 - Value of c is ", c
• a=2b=3
• c = a**b
• print "Line 6 - Value of c is ", c
Python Assignment Operators

Operator Example Same As

= x=5 x=5

+= x += 3 x=x+3

-= x -= 3 x=x-3

*= x *= 3 x=x*3

/= x /= 3 x=x/3
Python Assignment Operators

• LETS EVALUATE EACH LINE

• a = 21
• b = 10
• c=0
• c=a+b
• print "Line 1 - Value of c is ", c
• c += a
• print "Line 2 - Value of c is ", c
• c *= a
• print "Line 3 - Value of c is ", c
• c /= a
• print "Line 4 - Value of c is ", c
• c =2
• c %= a
• print "Line 5 - Value of c is ", c
• c **= a
• print "Line 6 - Value of c is ", c
Python Relational Operators

Operator Name Example

== Equal x == y

!= Not equal x != y

> Greater than x>y

< Less than x<y

>= Greater than or equal to x >= y

<= Less than or equal to x <= y


Python Logical Operators

Operator Name Example


and AND x < 5 and x < 10
or OR x < 5 or x < 4
not NOT not(x < 5)
TRUTH TABLE

E1 E2 E1 AND E2 E1 OR E2 NOT

T T T T F

T F F T F

F T F T T

F F F F T
PRACTICE EXERCISE :)

1. Create a program that uses 5 Arithmetic Operators in the given value from
the user.

.
PRACTICE EXERCISE :)

2. Create a program that can determine the relationship of the 2 values given
by the user
THANK YOU

You might also like