Search Header Logo
Python Operators

Python Operators

Assessment

Presentation

Information Technology (IT)

10th Grade

Practice Problem

Medium

Created by

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.

1

result = 3 + 2

2

result = 1.5*2

3

result = 18 / 6

4

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 ?

1

age = 3 + 10

print("You are ", age)

2

age = 12 + 2

print("You are ", 13)

3

print(You are 13)

4

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

Complete this piece of code to assign this variable a value of 45.

result = 3 ​
15
Drag these tiles and drop them in the correct blank above
*
/
+
-

10

Drag and Drop

Complete this piece of code to assign this variable a value of 7.

result = 42 ​
6
Drag these tiles and drop them in the correct blank above
/
+
-
*

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.

1

name = "John"

check = name == "Peter"

2

result1 = 3 * 15

result2 = 90 / 2

check = result1 == result2

3

result = 2 + 1

check = result == 3

4

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.

1

name = "Pete P"

check = name != "Peter"

2

result1 = 45

result2 = 5 * 9

check = result1 != result2

3

result = 5 - 1

check = result != 3

4

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

Add the correct operators into these lines of code to give each variable a value of true.

result = 3 ​
(6 / 2)

check = 4 ​
8

compare = 6 ​
3
Drag these tiles and drop them in the correct blank above
==
<=
>=

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

media

21

Multiple Select

Which of these lines of code will increase the variable score by 3 points. Check carefully - there are two correct answers.

1

score =+ 3

2

score = score + 3

3

score += 3

4

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)

1

result = 6%2

2

result = 19%2

3

result = 16%3

4

result = 21%3

28

Multiple Choice

Which of these will assign a value of true to the variable created?

1

result = 6%2 == 1

2

result = 19%2 >= 2

3

result = 16%3 >= 1

4

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

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

33

Match

Match the following

/

*

+=

=

**

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