[Tutor] sum of a list
Bill Mill
bill.mill at gmail.com
Wed Aug 11 01:41:47 CEST 2004
Jason,
try "sum(l_input)".
Otherwise, try:
def mysum(mylist):
sum = 0
for elt in mylist:
sum += elt
return sum
Peace
Bill Mill
----- Original Message -----
From: jason hochstein <bigapple631 at optonline.net>
Date: Tue, 10 Aug 2004 19:25:25 -0400
Subject: [Tutor] sum of a list
To: tutor at python.org
I can't figure out or find anywhere how to get the sum of a list??
Here is what I have so far:
l_input=[]
while True:
s = raw_input("Type number. Hit enter for more or type quit to finish: ")
if s == "quit":
break
else:
l_input.append(float(s))
print "Here is your list of numbers ", l_input
for i in l_input:
I am trying to get the sum of all numbers inputed so I can work with
the the total.
More information about the Tutor
mailing list