Monday, April 11, 2011

Python - Average and Sum

print "This program takes a list of any number, then displays the sum, and average of them."
print "Now please enter your numbers followed by a x."

listofnums = []
loop = 1

while (loop == 1):
   enterednum = raw_input()
   if enterednum == "x":
      loop = 0
      break
   else:
      listofnums.append (float(enterednum))
      del enterednum

print "here are all the numbers you entered."

for thelist in listofnums:
   print thelist
  
thesum = sum(listofnums)

numofvar = len(listofnums)
average = thesum / numofvar

print "The sum is:", thesum
print "And the average is:", average

raw_input()

No comments:

Post a Comment