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
15 changes: 15 additions & 0 deletions Lesson2/task10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
low = int(0)
high = int(101)
tries = 10
while tries > 0:
mytry = low + (high - low) // 2
print(f'Мое число {mytry}')
answer = input('Введите знак >, < или =: ')
if answer == '=':
print('Ура!')
exit(0)
if answer == '>':
high = mytry
if answer == '<':
low = mytry
tries = tries - 1
23 changes: 23 additions & 0 deletions Lesson3/task1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ans2 = ans3 = ans4 = ans5 = ans6 = ans7 = ans8 = ans9 =0
Copy link

Choose a reason for hiding this comment

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

Отлично, но не оптимально по объёму написания кода


SIZE = 100
for i in range(2, SIZE):
if i % 2 == 0:
ans2 += 1
if i % 3 == 0:
ans3 += 1
if i % 4 == 0:
ans4 += 1
if i % 5 == 0:
ans5 += 1
if i % 6 == 0:
ans6 += 1
if i % 7 == 0:
ans7 += 1
if i % 8 == 0:
ans8 += 1
if i % 9 == 0:
ans9 += 1

print (ans2, ans3, ans4, ans5, ans6, ans7, ans8, ans9)

14 changes: 14 additions & 0 deletions Lesson3/task2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import random
Copy link

Choose a reason for hiding this comment

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

Отлично


SIZE = 10
array = []
for _ in range(SIZE):
array.append(random.randint(0, SIZE * SIZE))

arrayb = []
for i in range(SIZE):
if array[i] % 2 == 0:
arrayb.append(i)

print(array)
print(arrayb)
19 changes: 19 additions & 0 deletions Lesson3/task3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import random
Copy link

Choose a reason for hiding this comment

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

Отличное решение


SIZE = 10
array = []
for _ in range(SIZE):
array.append(random.randint(0, SIZE * SIZE))

print(array)

maxpos = minpos = 0
for i in range(SIZE):
if array[i] > array[maxpos]:
maxpos = i
if array[i] < array[minpos]:
minpos = i

array[maxpos], array[minpos] = array[minpos], array[maxpos]

print(array)
30 changes: 30 additions & 0 deletions Lesson3/task4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import random

# Определяем параметры генерируемого массива SIZE - число элементов, RANGEMAX - максимальное значение каждого элемента
SIZE = 10
RANGEMAX = 10

#Определяем массив и заполняем случайными числами
array = []
for _ in range(SIZE):
array.append(random.randint(0, RANGEMAX))

# Определяем массив счетчиков
countarray = [0] * (RANGEMAX + 1)
Copy link

Choose a reason for hiding this comment

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

Представил задачу, где в массиве 10 чисел в диапазоне от нуля до миллиарда.
Неудачный алгоритм получается )))


# Считаем число вхождений каждого элемента исходного массива
for i in range(SIZE):
num = array[i]
countarray[num] +=1

# Ищем максимальное значение в массиве счетчиков
maxpos = 0
for i in range(RANGEMAX):
if countarray[i] > maxpos:
maxpos = i

# Выводим реузльтаты
print(array)
print(maxpos)


26 changes: 26 additions & 0 deletions Lesson3/task5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import random

# Определяем параметры генерируемого массива SIZE - число элементов, RANGEMAX - максимальное значение каждого элемента RANGEMIN - минимальное значение каждого элемента
SIZE = 10
RANGEMIN = -10
RANGEMAX = 10

#Определяем массив и заполняем случайными числами
array = []
for _ in range(SIZE):
array.append(random.randint(RANGEMIN, RANGEMAX))

#Выводим исходный массив
print(array)
minmax = RANGEMIN
Copy link

Choose a reason for hiding this comment

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

Алгоритм работает, когда вы точно знаете диапазон значений массива

minpos = 0

#Находим позицию максимального орицательного числа
for i in range(SIZE):
if array[i] < 0:
if array[i] > minmax:
minpos = i
minmax = array[i]

#Выводим максимальное отрицательное число и его позицию (с корректировкой)
print(array[minpos], minpos + 1)
26 changes: 26 additions & 0 deletions Lesson3/task6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import random
Copy link

Choose a reason for hiding this comment

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

Отлично


SIZE = 10
array = []
for _ in range(SIZE):
array.append(random.randint(0, SIZE * SIZE))

print(array)

maxpos = minpos = 0
for i in range(SIZE):
if array[i] > array[maxpos]:
maxpos = i
if array[i] < array[minpos]:
minpos = i

#Если позиция максимального выше позиции минимального - поменять их местами
if maxpos < minpos:
maxpos, minpos = minpos, maxpos

summ = 0

for i in range(minpos + 1, maxpos):
summ += array[i]

print(summ)