0% found this document useful (0 votes)
16 views1 page

Calculate Average of Five Numbers

The document outlines a Python script that prompts the user to enter five numbers, stores them in a list, and calculates their average. It includes a loop for user input, conversion of input to float, and the calculation of the average using the sum of the list divided by its length. Finally, it displays the calculated average to the user.

Uploaded by

musalijoshua43
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

Calculate Average of Five Numbers

The document outlines a Python script that prompts the user to enter five numbers, stores them in a list, and calculates their average. It includes a loop for user input, conversion of input to float, and the calculation of the average using the sum of the list divided by its length. Finally, it displays the calculated average to the user.

Uploaded by

musalijoshua43
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

# Initialize an empty list to store the numbers

numbers = []

• This line creates an empty list called where we'll store the five numbers entered by the user.

# Prompt the user to enter five numbers

for I in range (5):

num = float (input (f"Enter number {i+1}: "))

numbers. Append(num)

• starts a loop that runs five times (i.e., for to).

• asks the user to enter a number, showing which number they're entering (1 through 5).

• converts the input from a string to a floating-point number.

• adds the entered number to the list.

# Calculate the average

average = sum(numbers) / len(numbers)

• adds up all the numbers in the list.

• returns the number of items in the list (which is 5).

• Dividing the total sum by the count gives the average.

# Display the result

print (f"The average of the five numbers is: {average}

[Link]
%20Video%20-%[Link]

You might also like