Finding the average of a list

前端 未结 23 1589
抹茶落季
抹茶落季 2020-11-22 11:07

I have to find the average of a list in Python. This is my code so far

l = [15, 18, 2, 36, 12, 78, 5, 6, 9]
print reduce(lambda x, y: x + y, l)
23条回答
  •  情歌与酒
    2020-11-22 11:35

    numbers = [0,1,2,3]
    
    numbers[0] = input("Please enter a number")
    
    numbers[1] = input("Please enter a second number")
    
    numbers[2] = input("Please enter a third number")
    
    numbers[3] = input("Please enter a fourth number")
    
    print (numbers)
    
    print ("Finding the Avarage")
    
    avarage = int(numbers[0]) + int(numbers[1]) + int(numbers[2]) + int(numbers [3]) / 4
    
    print (avarage)
    

提交回复
热议问题