Computer Science, asked by richamishra207, 8 months ago

what role do logical operators play in if statement​

Answers

Answered by umeshprasad47998
2

Answer:

first follow me than I am answer

Answered by vaniviji06
0

Explanation:

The logical operators in Python (and, or, not) are often used in the if, if…else, and if…elif statements. They enable you to make multiple comparisons inside a single statement, such as to determine whether a value is within a certain range. Consider the following example:

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!')

Here is the output of the various inputs:

Enter your age: 14

You are too young or too old, go away!

>>>

Enter your age: 101

You are too young or too old, go away!

>>>

Enter your age: 25

Welcome, you are of the right age!

>>>

The code above checks to see if the user has entered a value less than 21 or greated than 101 (if x < 21 or x > 100) and if that is the case, informs the user that she is too young or too old. If the user enters any other number between 21 and 100, the Welcome, you are of the right age! message will be displayed.

Similar questions