Tuesday , April 20 2021

How to find the average value of a list in python

To answer the question of:

Please help me understand the problems in my code

The problem is the lines

to count the votes
if the count> = 50:
average = sum (count) / len (count)

vote it's a list of integers. So, when you loop to count the votes, the value of to count it's an integer I've tested your code in both Python 3.6.3 and 2.7.10 and you can not even call it sum() is len () it works on an integer (both return to TypeError if you try).

It initializes average = []so you seem to expect average to contain a list, but also if sum (count) = count is len (count) = 1, then average contains an integer, not a list.

I'd be curious to know which version of Python you're using that allows this code to run without errors.

Corrections for these errors have already been provided.

Source link

Leave a Reply

Your email address will not be published.