Averaging a list of user inputed numbers [Python] Pt. 1

Programming
Tutor: None Selected Time limit: 1 Day

Ok so this is what I'm being asked to do:

Write a program that asks the user to enter some numbers(pos, neg, and zeros).  Do NOT ask to enter a fixed set of numbers or the number of numbers you want to enter.  Ask to enter a few and end with -9999.  The program should create a list with the numbers entered but not to include -9999, then output the list with the following averages:

average of positive numbers, average of negative numbers, average of all the numbers

Current code in Pt. 2

May 1st, 2015

list_num =[]

[count_neg,count_pos,count_all] = [0,0,0]

[value_neg,value_pos,value_all]=[0,0,0]

while True:

    value = input("please enter number, if u want to close enter -9999 :")

    if value == -9999:

        break;

    if value <0:

        count_neg = count_neg +1

        value_neg = value_neg+value

    else:

        if value <0:

            count_pos = count_pos +1

            value_pos = value_pos+value

    list_num.append(value)

    count_all = 1+ count_all

print list_num

if count_pos==0:

    avg_pos = 0

else:

    avg_pos = value_pos/count_pos

if count_all==0:

    avg_all= 0

else:

    avg_all = value_all/count_all

if count_neg==0:

    avg_neg = 0

else:

    avg_neg = value_neg/count_neg

print [avg_pos,avg_neg,avg_all]


May 1st, 2015

A slight modification:

adding print statement to know the user value they are getting:


list_num =[]

[count_neg,count_pos,count_all] = [0,0,0]

[value_neg,value_pos,value_all]=[0,0,0]

while True:

    value = input("please enter number, if u want to close enter -9999 :")

    if value == -9999:

        break;

    if value <0:

        count_neg = count_neg +1

        value_neg = value_neg+value

    else:

        if value <0:

            count_pos = count_pos +1

            value_pos = value_pos+value

    list_num.append(value)

    count_all = 1+ count_all

print "List of numbers entered is: "

print list_num

if count_pos==0:

    avg_pos = 0

else:

    avg_pos = value_pos/count_pos

if count_all==0:

    avg_all= 0

else:

    avg_all = value_all/count_all

if count_neg==0:

    avg_neg = 0

else:

    avg_neg = value_neg/count_neg

print "Average is: "

print [avg_pos,avg_neg,avg_all]


May 1st, 2015

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
May 1st, 2015
...
May 1st, 2015
Dec 3rd, 2016
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer