A program for calculating the average height of schoolchildren — Python(Питон)

The Python program to calculate the average height of schoolchildren. To do this, you’ll need to collect the heights of the schoolchildren and then calculate the average.

Here’s an example program:

def calculate_average_height(heights):
    total_height = sum(heights)
    average_height = total_height / len(heights)
    return average_height

# Example usage
heights = []  # Create an empty list to store the heights

# Collect the heights from the user
num_children = int(input("Enter the number of schoolchildren: "))
for i in range(num_children):
    height = float(input(f"Enter the height of schoolchild {i+1} in centimeters: "))
    heights.append(height)

# Calculate the average height
average_height = calculate_average_height(heights)
print("Average height of schoolchildren:", average_height, "centimeters")

In this example program, we define a function calculate_average_height that takes a list of heights as input. It calculates the total height by summing all the heights in the list, and then divides it by the number of heights to get the average.

We first create an empty list heights to store the heights of the schoolchildren. We then ask the user to enter the number of schoolchildren num_children and loop over that number to collect each individual height from the user. Each height is appended to the heights list.

Finally, we call the calculate_average_height function with the heights list as input and print out the average height of the schoolchildren.

Leave a Comment