Answers for "calculate the average of highest 5 numbers in a list python"

4

find average of list python

list = [15, 18, 2, 36, 12, 78, 5, 6, 9]

# for older versions of python
average_method_one = sum(list) / len(list) 
# for python 2 convert len to a float to get float division
average_method_two = sum(list) / float(len(list))

# round answers using round() or ceil()
print(average_method_one)
print(average_method_two)
Posted by: Guest on October-03-2020
1

python average function program

#!/bin/python3

import math
import os
import random
import re
import sys


# write your code here
def avg(*n):
    sumOfNumber = 0
    for t in n:
        sumOfNumber = sumOfNumber + t
    avge = sumOfNumber / len(n)
    return avge
if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
    nums = list(map(int, input().split()))
    res = avg(*nums)
    
    fptr.write('%.2f' % res + 'n')

    fptr.close()
Posted by: Guest on June-18-2020
0

my_mode() python

>>> from collections import Counter

>>> def my_mode(sample):
...     c = Counter(sample)
...     return [k for k, v in c.items() if v == c.most_common(1)[0][1]]
...

>>> my_mode(["male", "male", "female", "male"])
['male']

>>> my_mode(["few", "few", "many", "some", "many"])
['few', 'many']

>>> my_mode([4, 1, 2, 2, 3, 5])
[2]

>>> my_mode([4, 1, 2, 2, 3, 5, 4])
[4, 2]
Posted by: Guest on October-29-2020

Code answers related to "calculate the average of highest 5 numbers in a list python"

Python Answers by Framework

Browse Popular Code Answers by Language