can you help me fix this code in the language python? The code need to print out
ID: 3792732 • Letter: C
Question
can you help me fix this code in the language python? The code need to print out a message" you didn't enter any number" when the input is only 0.
total = 0
posCount = 0
negCount = 0
count = 0
n = int(input("Enter the value(0 to quit): "))
while n != 0:
total = total + n
count = count + 1
if n < 0:
negCount = negCount + 1
n = int(input("Enter the value(0 to quit): "))
else:
posCount = posCount + 1
n = int(input("Enter the value(0 to quit): "))
average = total/float(count)
print ("Postive numbers count: ", posCount)
print ("Negative numbers count: ", negCount)
print ("Total: ", total)
print ("Average: ", average)
Explanation / Answer
Now your code is working please check it out.
total = 0
posCount = 0
negCount = 0
count = 0
n = int(input("Enter the value(0 to quit): "))
if n == 0:
print ("You entered 0, quiting...")
quit()
while n != 0:
total = total + n
count = count + 1
if n < 0:
negCount = negCount + 1
n = int(input("Enter the value(0 to quit): "))
else:
posCount = posCount + 1
n = int(input("Enter the value(0 to quit): "))
average = total/float(count)
print ("Postive numbers count: ", posCount)
print ("Negative numbers count: ", negCount)
print ("Total: ", total)
print ("Average: ", average)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.