..

Applying Knowledge - Class 4

Write a Python program that, given the age of an athlete typed by the user, displays a message from the column CATEGORY, just as shown in the table below, where the category depends on the age input by the user.

Note The CATEGORY must be displayed exactly as shown in the table below:

CATEGORY AGE
NOT ELIGIBLE TO BE AN ATHLETE Less than 5 years
CHILD A Between 5 and 7 years
CHILD B Between 8 and 10 years
JUNIOR A Between 11 and 13 years
JUNIOR B Between 14 and 17 years
SENIOR 18 years and older

Input:

  • Athelete’s age

Output:

  • CATEGORY, according to the athlete’s age as indicated in the table above.

Sample Inputs/Outputs:

foo@bar:~$ py baz.py
2
NOT ELEGIBLE TO BE AN ATHLETE
foo@bar:~$
foo@bar:~$ py baz.py
5
CHILD A
foo@bar:~$

SOLUTION:

x = int(input())

if x < 5:
    print('NÃO TEM IDADE PARA SER ATLETA')
elif 5 <= x <= 7:
    print('INFANTIL A')
elif 8 <= x <= 10:
    print('INFANTIL B')
elif 11 <= x <= 13:
    print('JUVENIL A')
elif 14 <= x <= 17:
    print('JUVENIL B')
else:
    print('SÊNIOR')

for fun:

print(next(c for c, a in (lambda x: {'NÃO TEM IDADE SUFICIENTE': x<5, 'INFANTIL A': 5<=x<=7, 'INFANTIL B': 8<=x<=10, 'JUVENIL A': 11<=x<=13, 'JUVENIL B': 14<=x<=17, 'SÊNIOR': x>17})(int(input())).items()if a))