
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
27 questions
Persuasive Techniques: Malala Nobel Prize Speech
Presentation
•
10th Grade
24 questions
Acids and Bases
Presentation
•
10th Grade
26 questions
Cell Transport
Presentation
•
9th - 10th Grade
26 questions
Sp. 3 Preterite Review
Presentation
•
9th - 10th Grade
25 questions
Leadership Styles
Presentation
•
10th Grade
28 questions
Problem and Solution
Presentation
•
10th Grade
28 questions
Absolute Monarchs
Presentation
•
10th Grade
24 questions
Ions
Presentation
•
10th Grade
Popular Resources on Wayground
20 questions
Math Review
Quiz
•
3rd Grade
15 questions
Fast food
Quiz
•
7th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
10 questions
Identify Fractions, Mixed Numbers & Improper Fractions
Quiz
•
3rd - 4th Grade
Discover more resources for Information Technology (IT)
10 questions
Fact Check Ice Breaker: Two truths and a lie
Quiz
•
5th - 12th Grade
10 questions
Video Games
Quiz
•
6th - 12th Grade
10 questions
Test Your Knowledge with 15 Fun Trivia Questions
Interactive video
•
6th - 10th Grade
15 questions
Memorial Day Trivia
Quiz
•
KG - 12th Grade
12 questions
Name that Candy
Quiz
•
KG - 12th Grade
20 questions
Guess The App
Quiz
•
KG - Professional Dev...
30 questions
K/H Final Review Part 1
Quiz
•
9th - 12th Grade
40 questions
NCFE Earth and Environmental Science Released Test
Quiz
•
9th - 12th Grade