From 2dca7409046a701c4d019aaa859634bdad36b488 Mon Sep 17 00:00:00 2001 From: Yesen Date: Thu, 9 Nov 2023 13:25:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20task4.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task4.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/task4.py b/task4.py index e69de29..9822fc0 100644 --- a/task4.py +++ b/task4.py @@ -0,0 +1,20 @@ +import sys +a = sys.argv[1] +nums = [] +with open (a, "r") as b: + nums = [int(line) for line in b] +sum = 0 +step = 0 +for num in nums: + sum+= num +avg_num_r = round(sum/ len(nums)) +for num in nums: + while num != avg_num_r: + if num > avg_num_r: + num -= 1 + step += 1 + elif num < avg_num_r: + num += 1 + step +=1 +print(step) + \ No newline at end of file