
Python Operators
Presentation
•
Information Technology (IT)
•
10th Grade
•
Practice Problem
•
Medium
Jillian Addison
Used 11+ times
FREE Resource
20 Slides • 13 Questions
1
Python Operators
Operators are special symbols, or combinations of symbols, that designate some type of computation.
2
+ - * /
We've met some of these operators already.
These are the basic mathematical operators.
3
Multiple Select
Which of these would assign a value of 3 to our variable called result? Choose all the answers that apply.
result = 3 + 2
result = 1.5*2
result = 18 / 6
result = 11 - 7
4
print()
Don't forget: we can use the print() command to display an output.
e.g. print(14-2)
would show 12 as an output
5
Concatenating
If we want to output several things at once, we can separate them with commas:
e.g. print("There are ", 3, " left")
would output: There are 3 left
6
Multiple Select
Which of these would produce the following output: You are 13 ?
age = 3 + 10
print("You are ", age)
age = 12 + 2
print("You are ", 13)
print(You are 13)
age = 13
Print(You are 13)
7
=
= does not work as a mathematical operator. Instead, = is used to assign a value to a variable.
e.g. name = "John Smith"
8
=
However, we can use = to assign a value to a variable that is the result of a calculation.
e.g. result = 3 + 5
print(result)
This will output the value 8.
9
Drag and Drop
result = 3
10
Drag and Drop
result = 42
11
==
This operator will check if two pieces of data are equal. If they are, it will return a value of true.
e.g. 2==2 will return a value of true
2==5 will return a value of false
12
==
This will also work for strings
e.g. "school" == "school" would return a value of true.
"skool" == "school" would return a value of false.
13
Multiple Select
Which of these will give the variable called check a value of true? Choose all the answers that apply. There are no errors in the code.
name = "John"
check = name == "Peter"
result1 = 3 * 15
result2 = 90 / 2
check = result1 == result2
result = 2 + 1
check = result == 3
username = "John"
check = username == "John"
14
!=
This works in a similar way, but checks for whether two values are different.
e.g. 4 != 4 would return a value of false.
4 != 1 would return a value of true
15
Multiple Select
Which of these will give the variable called check a value of false? Choose all the answers that apply. There are no errors in the code.
name = "Pete P"
check = name != "Peter"
result1 = 45
result2 = 5 * 9
check = result1 != result2
result = 5 - 1
check = result != 3
username = "John"
check = username != "John"
16
<= >=
These symbols mean "less than or equal to" and "more than or equal to".
e.g. 3 <= 7 would return a value of true
4 <= 2 would return a value of false
17
Drag and Drop
result = 3
check = 4
compare = 6
18
+= and -=
These operators are surprisingly important when writing slightly more complex code. They allow us to easily increase the value of a variable.
19
+= and -=
If I create a variable called score for a game, I would probably give it an initial value of 0, like this:
score = 0
20
+= and -=
I might want to increase the score by 10 points every time something correct is done in the game.
I could use the += operator.
e.g. score += 10
21
Multiple Select
Which of these lines of code will increase the variable score by 3 points. Check carefully - there are two correct answers.
score =+ 3
score = score + 3
score += 3
score = add 3
22
+= and -=
The -= will work similarly, but reduce the value each time.
If I wanted to take off 10 points for an error, I could write:
e.g. score -= 10
23
Less commonly used operators
The following operators are used less often...
24
%
The % operator will not calculate the percentage!
This operator returns the remainder of a calculation. This is called the modulus.
25
%
One use for this could be to work out whether a value is divisible by another value.
If the remainder is equal to 0, then the first value is divisible by the second number.
26
%
To illustrate how this would be written:
3%2 will return a value of 1
10%7 will return a value of 3
6%3 will return a value of 0
27
Multiple Select
Which of these will assign a value of 0 to the variable created? (i.e. there is no remainder)
result = 6%2
result = 19%2
result = 16%3
result = 21%3
28
Multiple Choice
Which of these will assign a value of true to the variable created?
result = 6%2 == 1
result = 19%2 >= 2
result = 16%3 >= 1
result = 21%3 != 0
29
**
This operator is used to indicate an exponent or 'power'.
i.e. 23 would be written 2**3 and would have a value of 8.
30
Match them up
Can you match the operator to its definition?
31
Match
Match the following
==
%
<=
!=
=
is equal to
finds the remainder
is less than or equal to
is not equal to
assigns a value
is equal to
finds the remainder
is less than or equal to
is not equal to
assigns a value
32
Match
Match the following
<=
>=
==
!=
**
is less than or equal to
is more than or equal to
is equal to
is not equal to
to the power of
is less than or equal to
is more than or equal to
is equal to
is not equal to
to the power of
33
Match
Match the following
/
*
+=
=
**
divided by
multiplied by
increases the value
assigns a value
to the power of
divided by
multiplied by
increases the value
assigns a value
to the power of
Python Operators
Operators are special symbols, or combinations of symbols, that designate some type of computation.
Show answer
Auto Play
Slide 1 / 33
SLIDE
Similar Resources on Wayground
23 questions
Covalent Bonds Notes
Presentation
•
10th Grade
24 questions
Solving Algebraic Proportions
Presentation
•
9th - 10th Grade
28 questions
simple machines
Presentation
•
10th Grade
27 questions
The Enlightenment
Presentation
•
10th Grade
27 questions
Sensory Details
Presentation
•
10th Grade
25 questions
Science Test Quizzes
Presentation
•
KG
27 questions
6.3 properties of parallelograms
Presentation
•
9th - 10th Grade
Popular Resources on Wayground
6 questions
PRIDE Always and Everywhere
Presentation
•
12th Grade
20 questions
Lab Safety Quiz
Quiz
•
6th Grade
26 questions
KOR Review Kahoot Questions
Quiz
•
8th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
12 questions
Unit Zero lesson 2 cafeteria
Presentation
•
9th - 12th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
10 questions
Riddles Riddles fun Riddles
Quiz
•
6th - 12th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
Discover more resources for Information Technology (IT)
12 questions
Unit Zero lesson 2 cafeteria
Presentation
•
9th - 12th Grade
10 questions
Riddles Riddles fun Riddles
Quiz
•
6th - 12th Grade
21 questions
Lab Safety
Quiz
•
10th Grade
10 questions
Would you Rather?
Quiz
•
9th - 12th Grade
20 questions
Characteristics of Life
Quiz
•
9th - 10th Grade
10 questions
Soup, Salad, or Sandwich?
Quiz
•
1st Grade - Professio...
10 questions
Labor Day and Its Historical Significance
Interactive video
•
7th - 12th Grade
20 questions
Scientific Method & Variables
Quiz
•
9th - 12th Grade