Answer the question
In order to leave comments, you need to log in
Logical operators in Python?
Hello everyone, I decided to write a simple program using a logical operator.
When writing code like this, it gives a syntax error:
age = float(input('Введите число:'))
if age <= 10:
print('Числ меньше или равно 10')
elif age > 10 or <= 25:
print('Число больше 10 или меньше или равно 25-и')
elif age > 25:
print('Число больше 25')
age = float(input('Введите число:'))
if age <= 10:
print('Числ меньше или равно 10')
elif age > 10 or age <= 25:
print('Число больше 10 или меньше или равно 25-и')
elif age > 25:
print('Число больше 25')
Answer the question
In order to leave comments, you need to log in
In the first case, they don’t write like this:
They write like this:
And even better like this:
In the second case, 25 already fell under the condition :
Therefore, the following if is not executed:
As a result, you can do this:
elif age > 10 or <= 25
elif age > 10 or age <= 25
elif 10 < age <= 25
elif age > 10 or age <= 25
elif age > 25
if age <= 10:
print('Числ меньше или равно 10')
elif 10 < age <= 25:
print('Число больше 10 или меньше или равно 25-и')
else:
print('Число больше 25')
At least for "greater than X, less than/[equal to} Y" you can use a trailing comparison.
age = float(input('Введите число:'))
if age <= 10:
print('Число меньше или равно 10')
elif 10 < age <= 25:
print('Число больше 10 или меньше или равно 25-и')
elif age > 25:
print('Число больше 25')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question