You are going to write a program that calculates the average student height from a List of heights.
student_heights = [180, 124, 165, 173, 189, 169, 146]
The average height can be calculated by adding all the heights together and dividing by the total number of heights.
180 + 124 + 165 + 173 + 189 + 169 + 146 = 1146
There are a total of 7 heights in
1146 ÷ 7 = 163.71428571428572
Average height rounded to the nearest whole number = 164
Important You should not use the
len() functions in your answer. You should try to replicate their functionality using what you have learnt about for loops.
156 178 165 171 187
In this case, student_heights would be a list that looks like: [156, 178, 165, 171, 187]
- Remember to use the
round()function to round the average height before you print it.
student_heights = input("Input a list of student heights ").split() for n in range(0, len(student_heights)): student_heights[n] = int(student_heights[n]) sum=0 i=0 for height in student_heights: sum=sum+height i=i+1 avg_height= sum/i print(round(avg_height))