[Tutor] Summing up numbers in a file

Robert Berman bermanrl at cfl.rr.com
Tue Oct 26 22:35:09 CEST 2010


This certainly looks like a classroom  assignment. Please make an attempt to
solve the problem on your own. If the program fails, please copy the code you
have written and the error messages from the traceback  and someone here will
be more than happy to help you work your way through the problem.

 

Good luck,

 

Robert

 

From: tutor-bounces+bermanrl=cfl.rr.com at python.org
[mailto:tutor-bounces+bermanrl=cfl.rr.com at python.org] On Behalf Of masawudu
bature
Sent: Tuesday, October 26, 2010 4:20 PM
To: tutor at python.org
Subject: [Tutor] Summing up numbers in a file

 

How do I sum all occurrences of  a number in a file?

I have a file with a bunch of numbers, each on it's own line:

 

5
3

11
3
7
3
5
5
11
7

7

...

How do i sum them up so that the output will be ,

5 :  15

3 :   9

11:  22

7 :   21

 


  _____  

I am using the Free version of SPAMfighter <http://www.spamfighter.com/len> .
SPAMfighter has removed 16 of my spam emails to date.

Do you have a slow PC? <http://www.spamfighter.com/SLOW-PCfighter?cid=sigen>
Try free scan! 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101026/68bbb7fb/attachment.html>


More information about the Tutor mailing list