Problem statement: Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.
示例输出(忽略项目符号,不知道如何将文本格式化为控制台输出):输入一个整数,如果是0:1,则输入结束
输入一个整数,如果是0:2,则输入结束
输入一个整数,如果为0,则输入结束:-1
输入一个整数,如果是0:3,则输入结束
输入一个整数,如果是0:0,则输入结束
你没有输入任何号码
阳性数是3
负片的数目是1
总数是5
平均值是1.25
尝试的解决方案: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):
最后
以上就是紧张航空最近收集整理的关于python数字计算公式_Python:(计算正数和负数并计算数字的平均值)的全部内容,更多相关python数字计算公式_Python:(计算正数和负数并计算数字内容请搜索靠谱客的其他文章。
发表评论 取消回复