Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Task_010.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 1. В диапазоне натуральных чисел от 2 до 99 определить, сколько из них кратны любому из чисел в диапазоне от 2 до 9.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отлично. И блок-схема тоже


a = [0] * 8
for i in range(2, 100):
for j in range(2, 10):
if i % j == 0:
a[j - 2] += 1
i = 0
while i < len(a):
print(i + 2, ' - ', a[i])
i += 1
15 changes: 15 additions & 0 deletions Task_020.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 2. Во втором массиве сохранить индексы четных элементов первого массива. Например, если дан массив со значениями 8, 3, 15, 6, 4, 2, то

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так же отлично

# во второй массив надо заполнить значениями 0, 3, 4, 5 (индексация начинается с нуля), т.к. именно в этих позициях первого массива
# стоят четные числа.

from random import random

N = 6
arr = [0] * N
even = []
for i in range(N):
arr[i] = int(random() * 10) + 10
if arr[i] % 2 == 0:
even.append(i)
print(arr)
print(f'Indices of even elements of the array N: {even}')
21 changes: 21 additions & 0 deletions Task_030.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 3. В массиве случайных целых чисел поменять местами минимальный и максимальный элементы.

from random import random

N = 10
arr = [0] * N
for i in range(N):
arr[i] = int(random() * 100)
print(arr[i], end=' ')
print()

mn = min(arr)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Как не просил обойтись без min и `max, но всё равно все делают с ними )))

mx = max(arr)
imn = arr.index(mn)
imx = arr.index(mx)
print(f'arr[{imn + 1}]={mn} arr[{imx + 1}]={mx}')
arr[imn], arr[imx] = arr[imx], arr[imn]

for i in range(N):
print(arr[i], end=' ')
print()
25 changes: 25 additions & 0 deletions Task_040.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 4. Определить, какое число в массиве встречается чаще всего.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отлично. Я бы даже сказал, что это классика


from random import random

N = 9
arr = [0] * N
for i in range(N):
arr[i] = int(random() * 10)
print(arr)

num = arr[0]
max_frq = 1
for i in range(N - 1):
frq = 1
for k in range(i + 1, N):
if arr[i] == arr[k]:
frq += 1
if frq > max_frq:
max_frq = frq

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут в блок-схеме потеряли стрелочку

num = arr[i]

if max_frq > 1:
print(f'{max_frq} times the number {num} is repeated')
else:
print('All items are unique')
20 changes: 20 additions & 0 deletions Task_050.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 5. В массиве найти максимальный отрицательный элемент. Вывести на экран его значение и позицию в массиве.

from random import random

N = 15
arr = []
for i in range(N):
arr.append(int(random() * 100) - 90)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А почему такие большие отступы внезапно?

print(arr)

i = 0
index = -1
while i < N:
if arr[i] < 0 and index == -1:
index = i

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так же нет стрелочек в блок-схеме. Впрочем, на оценку это не повлияет )))

elif arr[i] < 0 and arr[i] > arr[index]:
index = i
i += 1

print(f'The index of element in array is {index}\nThe element number is {arr[index]}')
28 changes: 28 additions & 0 deletions Task_060.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 6. В одномерном массиве найти сумму элементов, находящихся между минимальным и максимальным элементами.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Отлично

# Сами минимальный и максимальный элементы в сумму не включать.

from random import random

N = 10
a = [0] * N
for i in range(N):
a[i] = int(random() * 50)
print(f'{a[i]:2d}', end=' ')
print()

min_id = 0
max_id = 0
for i in range(1, N):
if a[i] < a[min_id]:
min_id = i
elif a[i] > a[max_id]:
max_id = i
print(f'Min array element is: {a[min_id]}\nMax array element is: {a[max_id]}')

if min_id > max_id:
min_id, max_id = max_id, min_id

summa = 0
for i in range(min_id + 1, max_id):
summa += a[i]
print(f'Sum of elements between max and min element is: {summa}')
30 changes: 30 additions & 0 deletions Task_070.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 7. В одномерном массиве целых чисел определить два наименьших элемента.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Классика. Отлично

# Они могут быть как равны между собой (оба являться минимальными), так и различаться.

from random import random

N = 10
a = []
for i in range(N):
a.append(int(random() * 100))
print(f'{a[i]:3d}', end='')
print()

if a[0] > a[1]:
min1 = 0
min2 = 1
else:
min1 = 1
min2 = 0

for i in range(2, N):
if a[i] < a[min1]:
b = min1
min1 = i
if a[b] < a[min2]:
min2 = b
elif a[i] < a[min2]:
min2 = i

print(f'#{min1:3d}:{a[min1]:3d}')
print(f'#{min2:3d}:{a[min2]:3d}')
20 changes: 20 additions & 0 deletions Task_080.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 8. Матрица 5x4 заполняется вводом с клавиатуры, кроме последних элементов строк.
# Программа должна вычислять сумму введенных элементов каждой строки и записывать
# ее в ее последнюю ячейку. В конце следует вывести полученную матрицу.

M = 5
N = 4
a = []
for i in range(N):
b = []
s = 0
print(f'{i} string:')
for j in range(M - 1):
n = int(input())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Молчаливый input. Напомните озвучить всем на уроке, чтоб не делали такого )))

s += n
b.append(n)
b.append(s)
a.append(b)

for i in a:
print(i)
25 changes: 25 additions & 0 deletions Task_090.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 9. Найти максимальный элемент среди минимальных элементов столбцов матрицы.

from random import random

M = 10
N = 5
a = []
for i in range(N):
b = []
for j in range(M):
n = int(random() * 200)
b.append(n)
print(f'{n:4d}', end='')
a.append(b)
print()

mx = -1
for j in range(M):
mn = 200

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Если в 11 строке изменить диапазон (например дописать в конце + 300, то уже не будет работать.
Ответ будет на уроке )))

for i in range(N):
if a[i][j] < mn:
mn = a[i][j]
if mn > mx:
mx = mn
print(f'Maximum of the minimum: {mx}')