countPositive = 0 countNegative = 0 count = 0 total = 0 num = int(input( "Enter an integer, the input ends if it is 0: ")) while num != 0: if num > 0: countPositive += 1 elif num < 0: countNegative += 1 total += num count += 1 # Read the next number num = int(input( "Enter an integer, the input ends if it is 0: ")) if count == 0: print("No numbers are entered except 0") else: print("The number of positives is", countPositive) print("The number of negatives is", countNegative) print("The total is", total) print("The average is", total / count)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question