Description
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
Explanation & Answer
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]
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
Dandelion Wine
by Ray Bradbury
Into Thin Air
by Jon Krakauer
Black Beauty
by Anna Sewell
The Two Towers
by J. R. R. Tolkien
The Glass Palace
by Amitav Ghosh
Cant Hurt Me - Master Your Mind and Defy the Odds
by David Goggins
The Color Purple
by Alice Walker
The Good Earth
by Pearl S. Buck
One Flew Over the Cuckoos Nest
by Ken Kesey