can you help me fix this code in the language python The cod
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)
Solution
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)
