Pobieranie danych, wartość średnia w python

Our task is to get multiple float values from user and return the average value in python.

We are going to take all the values at once, separated by spacebar.

We will use a split() method to create a list of values and map it to floats.

inp = input("Add values separated with spacebar: ")
strValues = inp.replace(",",".").split()
try:
    floatValues = list(map(float, strValues))
    average = sum(floatValues) / len(floatValues)
    print(f"Average value: {average}")
except:
    print("Error. Enter numeric values separated with spacebar")
Scroll to Top