0
I have a doubt in the following question:
Ages and heights of K students have been noted. Make a Program that determine how many students over 13 are below the height of average height of all students. Entry must contain a number N in the first line indicating the number of students in the test case. In followed, each row contains age and height.
My code is like this
idade = []
altura = []
somaAltura = []
cont = 0
qntAlunos = int(raw_input('Informe a quantidade de alunos: '))
for i in range(qntAlunos):
print 'Informe a idade:'
idade.append(int(raw_input()))
print 'Informe a altura:'
altura.append(float(raw_input()))
somaAltura = sum(altura)
media = somaAltura / qntAlunos
for j in range(qntAlunos):
if altura[j] < media and idade[j] > 13:
cont += 1
print cont
But because when I run the program, the counter never gives the correct answer?
"Then each line contains age and height", you are reading age and height in separate lines.
– Woss
You are calculating the sum of heights and the average and the back of the first one is. It doesn’t affect the result, but it would be more efficient to do this calculation outside the loop. And, as @Andersoncarloswoss said, there’s a problem with reading.
idade, altura = raw_input().split()
is about what you’ll need.– Cochise