Skip to content

Instantly share code, notes, and snippets.

@jklmli
Forked from anonymous/sum
Created May 17, 2011 02:02
Show Gist options
  • Save jklmli/975758 to your computer and use it in GitHub Desktop.
Save jklmli/975758 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
print("type integers, each followed by Enter; or ^D or ^Z to finish")
total = 0
count = 0
while True:
try:
line = input()
if line:
number = int(line)
total += number
count += 1
except ValueError as err:
print(err)
continue
except EOFError:
break
if count:
print("count = %i" % count, "total = %i" % total, "mean = %f" % (total/count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment