Summary - Operators
- Python course
- Beginner
- Lesson 29/116
- 5 min
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
# Combine operatorsSample solution
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
# Membership and comparisonSample solution
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
print(10 ____ 3)
print(10 % 3)
Explanation: % is the remainder (modulo) operator.