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

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.1.3 (Community Edition)

Windows 10

Python 3.7

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


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.