Answer the question
In order to leave comments, you need to log in
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
Because if the number is greater than 18, it is also greater than 10.
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.
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("Ты ещё ребенок!")
if age >= 18:
print("Поздравляю, вы уже взрослый!")
elif age >= 10:
print("Поздравляю, вы — подросток!")
else:
print("Вы ещё ребенок.")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question