From 1d2ba7c17375e87fe2a68bb9b3cdf9e05adff0b7 Mon Sep 17 00:00:00 2001 From: Oksgp Date: Thu, 23 Mar 2023 23:32:32 +0300 Subject: [PATCH] task_2.1 changed --- task_2.1.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/task_2.1.py b/task_2.1.py index 9ff9efa..bc80dc7 100644 --- a/task_2.1.py +++ b/task_2.1.py @@ -11,25 +11,21 @@ # функции max и min использовать нельзя! def minimum(arr): - min = arr[0] - i = 0 - for i in range(len(arr) - 1): - if len(arr) == 1: - min = arr[0] - elif arr[i + 1] <= arr[i]: - min = arr[i + 1] - return min + n = len(arr) + for i in range(n-1): + for j in range(n-i-1): + if arr[j] > arr[j+1]: + arr[j], arr[j+1] = arr[j+1], arr[j] + return arr[0] -print(minimum()) +print(minimum([-52, 56, 30, 29, -54, 0, -110])) def maximum(arr): - max = arr[0] - i = 0 - for i in range(len(arr) - 1): - if len(arr) == 1: - max = arr[0] - elif arr[i + 1] >= arr[i]: - max = arr[i + 1] - return max + n = len(arr) + for i in range(n-1): + for j in range(n-i-1): + if arr[j] > arr[j+1]: + arr[j], arr[j+1] = arr[j+1], arr[j] + return arr[-1] -print(maximum()) +print(maximum([-52, 56, 30, 29, -54, 0, -110]))