Search Header Logo
Arithmetic Operators

Arithmetic Operators

Assessment

Presentation

Computers

Vocational training

Practice Problem

Medium

Created by

Sakxam Shrestha

Used 4+ times

FREE Resource

19 Slides • 2 Questions

1

media

Arithmetic Operators

American Baptist College

2

media

Review: Data Types

What are they?

Classification for values
Why are they important?


How to use, change, combine each type

Exampl
integer, float, string, boolean

3

media

Review: Data Types

Data Type

Definition

Value Examples

integer (int)

number without a decimal point

5, -40, 0, 13382

float

number with a decimal point

3.14, 2.0, -9.5

string (str)

sequence of characters surrounded by quotes ‘abc’, “Hi!”, ‘3.14’

boolean (bool) True or False

True, False

4

media

Arithmetic Operators

5

media

Key Terms

operator: symbol performing specific computation on set of
values

expression: combination of operators and values evaluating
to single value

6

media

Evaluating expressions

2+4

operator

operands

expression

7

media

Arithmetic Operators

+ Add
-Subtract
* Multiply
/ Divide
**Exponent

8

media

If any operand is float, evaluated value is float
1 + 2.0 => 3.0 (not 3)

If all operands are integers, evaluated value is integer
4 * 3 => 12 (not 12.0)

EXCEPT DIVIDE /- evaluated value is always float
12 / 4 => 3.0
12.0 / 4.0 => 3.0
12.0 / 4 => 3.0

Arithmetic Operators: Floats, Integers

9

Multiple Choice

What will be the result of the following operation?
5 + 7.0

1

12

2

12.0

3

12.00

4

Error

10

media

+ Add
"And" + "rea" => "Andrea"

Arithmetic Operators: Strings

Adding strings together is called
concatenation.

* Multiply
"hello" * 2 => "hellohello"
Note: string multiplication only exists in Python

11

media

// divides two numbers and rounds result down to next whole number
Examples:
5 // 2 evaluates to 2
5.0 // 2.0 evaluates to 2.0
42 // 10 evaluates to 4
9 // 9 evaluates to 1
9.0 // 9.0 evaluates to 1.0

Operator: Floor Division

12

media
media

Operator: Modulo

% computes remainder after division
Examples:
5 % 2 evaluates to 1
5.0 % 2.0 evaluates to 1.0
24 % 10 evaluates to 4
9 % 9 evaluates to 0
9.0 % 9.0 evaluates to 0.0

13

media

Order of Operations

Parentheses
Exponents
Multiplication
Division
Addition
Subtraction

MD and AS have the same precedence, go left to right

MD, //, and % have the same precedence, go left to right

14

Multiple Choice

What is the result of the following expression?
2 + 3 * 4

1

14

2

20

3

24

4

9

15

media

PEMDAS

2 + 1 * 5 - 6 / 2

3 + (1 + 4) * 2

'h' + 'i' * 3

2 + 5 - 3.0
=

4.0

=3 + 5 * 2
= 13

= 'h' + 'iii' =' hiii'

16

media

What happens?

"5" + 5
TypeError: cannot concatenate 'str' and 'int' obj
How to fix this?
"5" + str(5)

17

media
media

Functions

function: performs specific action
on a set of values
Takes inputs
Performs task on inputs
Optionally, gives output

Inputs and outputs of a function are values.

18

media

Built-in functions

type()determines data type of input value
int()converts input value to an integer
float()converts input value to a float
str()converts input value to a string
bool()converts input value to a boolean

19

media

Type Conversions

Convert numbers to other type by using int() and float() functions

int(5)

5

int(3.42)

3

float(5)

5.0

float(5.6)

5.6

str(5)

"5"

str(int(2.8))

"2"

Does calling int() with an int or float() with a float change the value?

20

media

Review: Expressions, Functions

Values and operators make up expressions
Computers evaluate expressions down to a single value

2+4

operator

operands (values)

expression

Functions perform an action on input value(s) to compute a result
type() int() float() str() bool()

21

media

If any operand is float, evaluated value is float
If all operands are integers, evaluated value is integer
EXCEPT DIVIDE /- evaluated value is always float

Review: Arithmetic Operators

// Floor Division
Round down to nearest whole number

% Modulo (mod)
Remainder

PEMDAS
Order of operations

+ Add
-Subtract
* Multiply
/ Divide
**Exponent

media

Arithmetic Operators

American Baptist College

Show answer

Auto Play

Slide 1 / 21

SLIDE