Created
October 30, 2021 08:36
-
-
Save naemazam/e0ac76224e92d4d80d3e6ae873df5de3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' Enter a non-zero integer from the keyboard, take the input of 0 as the | |
input end flag, calculate the average value, and count the number of | |
positive and negative numbers | |
[input form] | |
One line per integer. The last line is 0, indicating the end of | |
input. | |
[output form] | |
Output three lines. | |
The first line is the average. The second line is a positive number. | |
The third line is the number of negative numbers. | |
[sample input] | |
1 | |
1 | |
1 | |
0 | |
[sample output] | |
1.0 | |
3 | |
0 | |
''' | |
def main(): | |
i = int( input ("Enter an interger, the input ends if it is 0: ")) | |
count_pos = 0 | |
count_neg = 0 | |
total = 0 | |
if (i != 0): | |
while (i != 0): | |
if (i > 0): | |
count_pos += 1 | |
elif (i < 0): | |
count_neg += 1 | |
total += i | |
i = int( input ("Enter an interger, the input ends if it is 0: ")) | |
count = count_pos + count_neg | |
average = total / count | |
print ("The number of positives is", count_pos) | |
print ("The number of negatives is", count_neg) | |
print ("The total is", total) | |
print ("The average is", float(average)) | |
else: | |
print ("You didn't enter any number.") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment