Ifelse statement A simple question.

Asked 2 years ago, Updated 2 years ago, 99 views

age = int("Enter your age")
if age >= 20:
        print('you are adult')
elif age >=10 or age < 20:
    print('you are adolescent')
elif age < 10:
    print('you are baby')

I made the code like this, but even if I put 10 or less in the last code, "you are adolescent" is printed out.

The problems are as follows:

Let's write a program that prints "you are adult" when you are over 20 years old, "you are adolescent" for those over 10 years old and "you are baby" for those under 10 years old.

python if-else

2022-09-20 19:20

1 Answers

It's a very simple problem.

elif age >=10 or age < 20:
    print('you are adolescent')

If you use or here, age < 20, age> = 10 everything that satisfies it is included, so you say the whole mistake,

if age >= 20:
        print('you are adult')

Any mistakes that are not applicable to must be applicable. Therefore, you can change or to and to satisfy both conditions at the same time.

elif age >=10 and age < 20:
    print('you are adolescent')


2022-09-20 19:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.