Skip to content

Instantly share code, notes, and snippets.

@DOOMer
Last active December 24, 2015 04:19
Show Gist options
  • Save DOOMer/6743149 to your computer and use it in GitHub Desktop.
Save DOOMer/6743149 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
# список для сохзранения введенных данных
input_list = []
n = 0 # сюда будем вводить числа
while not n < 0: # пока n не отрицательно
# просим пользователя ввести число
n = float(input("Enter the num: "))
# и добавляем это число в список
input_list.append(n)
# при вводе отрицательного числа происходит выход из цикла white
# и вычисление среднего арифметического введенных чисел
# (исключая последнее, отрицательное)
print(sum(input_list[:-1])/(len(input_list)-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment