2
My code needs to read multiple numbers and put them in a list, then create two extra lists containing only even and odd values respectively from the previous list.
Example:
Entrada = [3, 7, 8, 11, 16, 20]
Saída = Lista completa: [3, 7, 8, 11, 16, 20]
Lista de pares: [8, 16, 20]
Lista de ímpares: [3, 7, 11]
But the values are not being added in the lists of even and odd numbers, what is the problem with my code?
valores = pares = impares = list()
while True:
valores.append(int(input('Digite um valor: ')))
continuar = ' '
while continuar not in 'SN':
continuar = str(input('Continuar? [S / N] ')).upper()[0]
if continuar in 'N':
break
print(f'Lista completa: {valores}')
for num in valores:
if num % 2 == 0:
pares.append(num)
else:
impares.append(num)
print(f'Lista de pares: {pares}')
print(f'Lista de ímpares: {impares}')
Your reply does not take into account that the algorithm must be implemented in order to receive n values according to the user.
– Evilmaax