[Python-Help] Programming help

Bob Gailer bgailer at alum.rpi.edu
Tue Dec 7 01:43:39 CET 2004

At 07:07 PM 12/5/2004, Alfred Canoy wrote:
>Please help me out:(.. I've been trying to figure this out for 2 days now..
>I don't know what to use to print  all the list of numbers. I hve know 
>idea how should I do this. I tried a lot of trial & error for the the def, 
>dict, .list( ). have no luck.
>I just need to find this out then I'm good to go for the whole thing. I 
>have save the other test source code for this problem. I just need to 
>combine it after I figure this out.
>Thank you all!
>Source code:
># compute the Mean, Median & Mode of a list of numbers:
>sum = 0.0
>print 'This program will take several numbers then average them'
>count = input(' How many numbers would you like to sum: ')
>current_count = 0
>freq = {}
>freq [current_count] = number
>while current_count < count:
>    current_count = current_count + 1
>    number = input ('Enter a number: ')
>    print "Number", current_count,":",number
>    sum = sum + number
>print " [x,...,x] ?"

It's hard to respond since there is so much amiss in your code. Inside the 
while loop you need to append each user entry to a list. Then you can print 
the list. Have you studied list operations in a tutorial?

Also it is unclear what you intend by freq [current_count] = number. There 
is no variable named "number" at that point in the program, so the program 
should crash at that statement. I think you want that statement inside the 
loop also, although it is not doing anything useful. If you want to capture 
frequencies you need to use the number as a dictionary key, and increment 
the value under that key.

Clean things up as best you can then come back for the next round.

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell 

More information about the Python-list mailing list