CodeBlanks Logo Icon CodeBlanks

Summary - Operators

Combine arithmetic, comparison and logical operators to write a grade calculator.

Summary - Operators

In this group you learned arithmetic, comparison, logical, bitwise and membership/identity operators.

  • Arithmetic: +, -, *, /, %, **, //
  • Comparison: ==, !=, <, >, <=, >=
  • Logical: and, or, not
  • Bitwise: &, |, ^, ~, <<, >>
  • Membership/identity: in, is

Now two tasks combine these concepts.

Practice Combine operators

Assign age = 20. Print print(age >= 18 and age <= 65).

Starter code

main.py
# Combine operators

Sample solution

main.py
age = 20
print(age >= 18 and age <= 65)

Expected output

True

Practice Membership and comparison

Assign score = 85. Print print(score >= 50 and score <= 100) and print(85 in [50, 85, 100]).

Starter code

main.py
# Membership and comparison

Sample solution

main.py
score = 85
print(score >= 50 and score <= 100)
print(85 in [50, 85, 100])

Expected output

True
True

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which is wrong?

  • % gives remainder
  • ** does power
  • // is floor division
  • and is the bitwise and operator Correct answer

Explanation: and is logical and, bitwise and is &.

2 Remainder operator

Question
print(10 ____ 3)
Answer
print(10 % 3)

Explanation: % is the remainder (modulo) operator.

All lessons in Beginner