K
K
kudlenkov3032021-11-10 21:20:37
Python
kudlenkov303, 2021-11-10 21:20:37

Why doesn't the elif condition work?

Why the elif condition does not want to be fulfilled. When you enter an age of 18 or above, the program displays Congratulations you are a teenager!

name = input("Введите своё имя >>> ")
age = int(input("Введите свой возраст >>> "))
print("Привет, "+ name)
if age >= 10:
   print("Поздравляю ты подросток!")
elif age >= 18:
   print("Поздравляю ты уже взрослый!") 
else:
   print("Ты ещё ребенок!")

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vindicar, 2021-11-10
@kudlenkov303

Because if the number is greater than 18, it is also greater than 10.

S
Sergey Gornostaev, 2021-11-10
@sergey-gornostaev

Because the code was written by a teenager. Obviously, if the variable age contains a value such as 20, then it is greater than 10, the first condition is triggered, and the others are not checked.

K
kudlenkov303, 2021-11-10
@kudlenkov303

Here is a program that really works.
I already figured out the code and fixed the bug.

name = input("Введите своё имя >>> ")
age = int(input("Введите свой возраст >>> "))

print("Привет, "+ name)
if age >= 18:
   print("Поздравляю ты уже взрослый!") 
elif age >= 10 < 18:
   print("Поздравляю ты подросток!")
else:
   print("Ты ещё ребенок!")

K
Konstantin Tsvetkov, 2021-11-16
@tsklab

if age >= 18:
   print("Поздравляю, вы уже взрослый!") 
elif age >= 10:
   print("Поздравляю, вы — подросток!")
else:
   print("Вы ещё ребенок.")

Because the second one will be checked for age less than 18.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question