Relational, Logical and Assignment Operators
This is a free course. Log in to run the code exercises and track your progress.
Relational, Logical and Assignment Operators
Relational operators compare two values and give True or False: == (equal to), != (not equal to), >, <, >= and <=. Do not confuse == (comparison) with = (assignment).
Logical operators combine conditions:
andis True only when both sides are True.oris True when at least one side is True.notreverses a value:not TrueisFalse.
marks = 72
print(marks >= 33) # True
print(marks >= 33 and marks < 75) # True: passed, but no distinction
print(not marks == 72) # False
Assignment operators store a value. The shortcut forms update a variable: count += 1 means count = count + 1; -=, *= and /= work the same way.
Read a student's marks (out of 100). Print True on the first line if the student passed (33 or more), and on the second line True if the marks are a distinction (75 or more), else False.
marks = int(input())
print(marks > 100) # replace with the pass condition
print(marks > 100) # replace with the distinction conditionLog in to edit and run this code.