Skip to content

Python If-Else Statement with OR Operator in Condition/Expression | Example code

  • by

Example code use or operator to combine two basic conditional expressions in Python If-Else Statement.

In the example taking input value from the user.

x = int(input('Enter your age: '))

if x < 21 or x > 100:
    print('You are too young or too old, go away!')
else:
    print('Welcome, you are of the right age!')

Output:

Python If-Else Statement with OR Operator in Condition/

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading