On 25/10/16 09:09, niraj pandey wrote: > Try this. > > my_string = '0,1,2,3' > my_lst=my_string.split(",") > leng = len(my_lst) > b=sum(my_lst) > avg=float(b/leng) > print avg
It doesn't work because my_list is a list of strings and you can't sum() strings. The loop is needed to convert the strings to numbers. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor