0
Below is the code I am using, this presenting the following error:
SyntaxError: invalid syntax
maycon@maycon-H14SU08:~/Documentos/Algoritimos$ python3 prova_lista.py
File "prova_lista.py", line 23
elif 18 pessoas <= 65:
Make a program that, using a repeat loop, receives the age of 10 people, calculate and show the amount of people in each age group according to the legend:
- Minor - 0 to 17 years old
- Young - 18 to 65 years old
- Middle age - 66 to 79 years old
- Aged - 80 to 99 years
- Long-lived elderly - 100 or more
pessoas = [""] * 10
i = 0
soma = 0
while i < len(pessoas):
pessoas[i] = int(input("Digite a sua idade: "))
soma = soma + pessoas[i]
i = i + 1
i = 0
soma = 0
while i < len(pessoas):
pessoas = pessoas[i]
pessoas = int(pessoas)
soma = soma + pessoas
i = i + 1
if pessoas < 17:
print("--- Menor de Idade ----")
break
elif 18 < pessoas <= 65:
print("--- Jovem ---")
break
elif 66 < pessoas <= 79:
print("--- Meia Idade ---")
break
elif 80 < pessoas <= 90:
print("--- Idoso ---")
break
elif pessoas >= 100:
print("--- Idoso de Vida Longa ---")
break
I understand, but still presenting the error: Traceback (Most recent call last): File "prova_lista.py", line 20, in <module> if people <= 17: Typeerror: '<=' not supported between instances of 'list' and 'int'
– Maycon Willian Alves da Silva
Yes @Mayconwillianalvesdasilva, but this is another different error, caused by another problem, this time of logic - you can not compare lists with numbers.
– nosklo
Ok, in case I should convert the list to whole. The program runs normally, but only displays the first age group in the if block.
– Maycon Willian Alves da Silva
@Mayconwillianalvesdasilva I think you do not need a list, after all, the statement did not have to store all people. You edited the question but the error remains the old one, edit also the error
– nosklo
@Mayconwillianalvesdasilva edited my answer and put an example of solution to your problem, I hope to have helped, if you have any questions in understanding can open another question or if it is the case, ask here
– nosklo