Skip to content

Instantly share code, notes, and snippets.

/sum

Created May 17, 2011 01:42
Show Gist options
  • Save anonymous/975732 to your computer and use it in GitHub Desktop.
Save anonymous/975732 to your computer and use it in GitHub Desktop.
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 =", count, "total =", total, "mean =", total/count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment