This commit is contained in:
2021-07-31 17:10:28 +04:00
commit 8eaa630f67
12 changed files with 337 additions and 0 deletions

51
ch4/bubbles.py Normal file
View File

@@ -0,0 +1,51 @@
scores = [
60, 50, 60, 58, 54, 54, 58, 50, 52,
54, 48, 69, 34, 55, 51, 52, 44, 51,
69, 64, 66, 55, 52, 61, 46, 31, 57,
52, 44, 18, 41, 53, 55, 61, 51, 44
]
costs = [
.25, .27, .25, .25, .25, .25,
.33, .31, .25, .29, .27, .22,
.31, .25, .25, .33, .21, .25,
.25, .25, .28, .25, .24, .22,
.20, .25, .30, .25, .24, .25,
.25, .25, .27, .25, .26, .29
]
# i = 0
length = len(scores)
max = 0
min = 0
max_list = []
# while i < length:
for i in range(length):
print('Пузырьковый раствор #' + str(i), '- результат:', scores[i])
# i += 1
if max < scores[i]:
max = scores[i]
print('Пузырьковых тестов:', length)
print('Наибольший результат:', max)
for i in range(length):
if scores[i] == max:
max_list.append(i)
cost = 100.0
most_effective = 0
# for i in range(len(costs)):
# if scores[i] == max and costs[i] <= cost:
# most_effective = i
# cost = costs[i]
# for i in max_list:
# if costs[i] <= cost:
# most_effective = i
# cost = costs[i]
for i in range(len(max_list)):
index = max_list[i]
if cost > costs[index]:
most_effective = index
cost = costs[index]
print('Наибольший результат:', max_list)
print('Раствор:', most_effective, 'самый выгодный, его цена -', cost)

16
ch4/scores.py Normal file
View File

@@ -0,0 +1,16 @@
scores = [
60, 50, 60, 58, 54, 54, 58, 50, 52,
54, 48, 69, 34, 55, 51, 52, 44, 51,
69, 64, 66, 55, 52, 61, 46, 31, 57,
52, 44, 18, 41, 53, 55, 61, 51, 44
]
i = 0
max = 0
for i in range(len(scores)):
print('Пузырьковый раствор #', i, '- результат:', scores[i])
if max < scores[i]:
max = scores[i]
print('Пузырьковых тестов:', i)
print('Наибольший результат:', max)
print(max in scores)

27
ch4/sort.py Normal file
View File

@@ -0,0 +1,27 @@
scores = [
60, 50, 60, 58, 54, 54, 58, 50, 52,
54, 48, 69, 34, 55, 51, 52, 44, 51,
69, 64, 66, 55, 52, 61, 46, 31, 57,
52, 44, 18, 41, 53, 55, 61, 51, 44
]
number_of_list = len(scores)
solution_numbers = list(range(number_of_list))
def bubble_sort(list, numbers):
swapped = True
while swapped:
swapped = False
for i in range(len(list)-1):
if list[i] < list[i+1]:
temp = list[i]
list[i] = list[i+1]
list[i+1] = temp
temp = numbers[i]
numbers[i] = numbers[i + 1]
numbers[i + 1] = temp
swapped = True
for i in range(0, 5):
print(str(i + 1) + '.', 'Пузырьковый раствор №' + str(solution_numbers[i]), '- результат:', scores[i])
bubble_sort(scores, solution_numbers)

16
ch4/super.py Normal file
View File

@@ -0,0 +1,16 @@
characters = 'wasitar'
output = ''
length = len(characters)
i = 0
while (i < length):
output = output + characters[i]
i += 1
length = length * -1
i = -2
while (i >= length):
output = output + characters[i]
i = i -1
print(output)