Solution: Compute the Average of an Arbitrary Number of Inputs
Learn how to receive an arbitrary number of float inputs and compute their average.
We'll cover the following...
The solution to the problem of receiving an arbitrary number of float
inputs and computing their average is given below.
Solution
Press + to interact
# Enter the total number of inputs the user wants to enter e.g., 3# then press enter/return# Enter all number in a single line, use space as a delimiter e.g., 2.0 5.0 8.0# then click the "Run" buttonnum = int(input('How many numbers do you wish to input: '))print(num)totalsum = 0number = [float(x) for x in input('Enter all numbers: ').split( )]print(number)for n in range(len(number)) :totalsum = totalsum + number[n]avg = totalsum / numprint('Average of', num, 'numbers is:', avg)
Enter the input below