Python Forum
Error is finding mean of a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error is finding mean of a list
#2
Python interactive interpreter is your best friend.

>>> a = []
>>> len(a)
0                               
>>> # source of ZeroDivsionError
>>> data = input('Please enter integers separated by comma: ').split(',')
Please enter integers separated by comma: 1,2,3
>>> data
['1', '2', '3']
>>> sum(int(i) for i in data)/len(data)
2.0                          
>>> # returns float
>>> import statistics.  
>>> # built-in module
>>> statistics.mean(int(i) for i in data)
2                          
>>> # returns int
I don't recommend to use capitalized built-ins as names.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Error is finding mean of a list - by PythonBoy - Sep-10-2023, 07:26 AM
RE: Error is finding mean of a list - by perfringo - Sep-10-2023, 08:53 AM
RE: Error is finding mean of a list - by PythonBoy - Sep-10-2023, 11:33 AM
RE: Error is finding mean of a list - by perfringo - Sep-11-2023, 04:57 AM
RE: Error is finding mean of a list - by PythonBoy - Sep-11-2023, 02:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Finding combinations of list of items (30 or so) LynnS 1 921 Jan-25-2023, 02:57 PM
Last Post: deanhystad
Question Finding string in list item jesse68 8 1,982 Jun-30-2022, 08:27 AM
Last Post: Gribouillis
  Finding an element in a 1d list in a 2d array lionrocker221 0 1,870 Jun-27-2020, 04:50 PM
Last Post: lionrocker221
  capture next block of text after finding error in file kdefilip2 6 3,546 Nov-27-2019, 07:36 PM
Last Post: buran
  Finding MINIMUM number in a random list is not working Mona 5 3,115 Nov-18-2019, 07:27 PM
Last Post: ThomasL
  finding the closest floating point number in a list Skaperen 17 8,567 Sep-19-2019, 10:39 PM
Last Post: Skaperen
  Finding exact phrase in list graham23s 2 2,966 Mar-13-2019, 06:47 PM
Last Post: graham23s
  I need help finding an error in this code I have Tacnoblode 1 2,739 Jul-18-2018, 05:51 AM
Last Post: buran
  finding similar objects in a list DRPR 4 108,130 Jun-22-2018, 10:05 AM
Last Post: volcano63
  Getting error in finding time.time() value in python Lakshana 1 2,528 Jan-11-2018, 07:07 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020