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.Python: (Count положительных и отрицательных чисел и вычислить среднее значение чисел)
Пример вывода (игнорировать пули, не знаю, как форматировать текст в консоли вывода):
- Введите целое число, вход заканчивается, если он равен 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):
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()
Что вы, делаете? – Tetramputechture
Оператор проблемы находится в верхней части блока, который помечен как «Заявление о проблемах:» –
Какие ошибки вы получаете в своем выпуске? – Tetramputechture