This commit is contained in:
2026-04-18 14:42:00 +05:00
commit ef77f101fa
96 changed files with 3134 additions and 0 deletions

10
labPython/lab5/DArray14.py Executable file
View File

@@ -0,0 +1,10 @@
from random import randint
from MatrixMethods import initnxnMatrix, printMatrix, divideEvenColumnsMainDiagonal
x = int(input("Введите размерность матрицы: "))
Array = initnxnMatrix(x)
print("Матрица раньше:")
printMatrix(Array)
Array = divideEvenColumnsMainDiagonal(Array)
print("Матрица сейчас:")
printMatrix(Array)

15
labPython/lab5/DArray2.py Executable file
View File

@@ -0,0 +1,15 @@
from MatrixMethods import printMatrix, transDiagonalMatrix
from random import randint
n = (int(input("введите размеров массивов: "))%11)
Matrix = [[randint(1, 100) for _ in range(n)] for _ in range(n)]
print("Mатрица до изменений:\n\n")
printMatrix(Matrix)
print("\n\n")
for index, stroke in enumerate(Matrix):
Matrix[index] = transDiagonalMatrix(stroke, index )
print("Mатрица после изменений:\n\n")
printMatrix(Matrix)
print("\n\n")

32
labPython/lab5/MatrixMethods.py Executable file
View File

@@ -0,0 +1,32 @@
from random import randint
def initnxnMatrix(count:int)->list[list]:
Array = [[randint(1, 100) for _ in range(count)] for _ in range(count)]
return Array
def printMatrix(Array:list[list])->None:
for i in range(len(Array)+1):
print(f"{i}\t", end="")
print("")
for index in range(len(Array)):
print(f"{index+1}\t", end="")
for value in Array[index]:
print(f"{value}\t", end="")
print("")
def transDiagonalMatrix(Array:list[list], i:int)->list:
if Array[i] != Array[-(i+1)]:
Array[i] += Array[-(i+1)]
Array[-(i+1)] = Array[i] - Array[-(i+1)]
Array[i] = Array[i] - Array[-(i+1)]
return Array
def divideEvenColumnsMainDiagonal(Array:list[list])->list[list]:
mainDiagonal = 0
for index, element in enumerate(Array):
mainDiagonal += element[index]
for elementIndex, element in enumerate(Array):
for index in range(len(element)):
if (index + 1)%2==0:
Array[elementIndex][index] //= mainDiagonal
return Array

21
labPython/lab5/Slov14.py Executable file
View File

@@ -0,0 +1,21 @@
candies = {
"Шоколадные": {"price": 150, "shelf_life": "12 месяцев", "shops": [1, 3, 5]},
"Карамель": {"price": 80, "shelf_life": "6 месяцев", "shops": [2, 4]},
"Трюфели": {"price": 150, "shelf_life": "18 месяцев", "shops": [1, 2, 3]},
"Мармелад": {"price": 120, "shelf_life": "9 месяцев", "shops": [2, 5]},
"Ириски": {"price": 950, "shelf_life": "8 месяцев", "shops": [1, 3, 4]},
"Вафли": {"price": 1800, "shelf_life": "10 месяцев", "shops": [3, 4, 5]},
"Пряники": {"price": 110, "shelf_life": "7 месяцев", "shops": [1, 2]}
}
for name, info in candies.items():
if 100 <= info["price"] <= 200:
print(f"{name}:")
print(f" Срок годности: {info['shelf_life']}")
shops_str = ""
for i in range(len(info['shops'])):
if i > 0:
shops_str += ", "
shops_str += str(info['shops'][i])
print(f" Магазины: {shops_str}")

12
labPython/lab5/Slov32.py Executable file
View File

@@ -0,0 +1,12 @@
books = [
{"author": "Толстой", "title": "Война и мир", "year": 1869},
{"author": "Пушкин", "title": "Евгений Онегин", "year": 1833},
{"author": "Кнут", "title": "Искусство программирования", "year": 1968},
{"author": "Таненбаум", "title": "Архитектура компьютера", "year": 1976},
{"author": "Столл", "title": "Введение в информатику", "year": 1985},
{"author": "Уоррен", "title": "Алгоритмические трюки для программистов", "year": 2002},
{"author": "Кнут", "title": "Конкретная математика", "year": 1994},
{"author": "Столл", "title": "Основы информатики", "year": 1970},
{"author": "Пушкин", "title": "Руслан и Людмила", "year": 1820},
{"author": "Таненбаум", "title": "Современные операционные системы", "year": 1992},
]

12
labPython/lab5/Slov9.py Executable file
View File

@@ -0,0 +1,12 @@
string = input()
count = {}
result = ""
for char in string:
if char not in count:
count[char] = 0
else:
count[char] += 1
result += f"{char}_{count[char]}"
print(result)

20
labPython/lab5/Spis12.py Executable file
View File

@@ -0,0 +1,20 @@
ArrayStatic = (1, 2, 34, 53, 20, 10)
maxNum = 0
maxIndex = 0
minNum = ArrayStatic[0]
minIndex = 0
for index in range(0, len(ArrayStatic)):
if maxNum < ArrayStatic[index]:
maxNum = ArrayStatic[index]
maxIndex = index
if minNum > ArrayStatic[index]:
minNum = ArrayStatic[index]
minIndex = index
print(ArrayStatic)
ArrayStatic = list(ArrayStatic)
ArrayStatic[maxIndex] = minNum
ArrayStatic[minIndex] = maxNum
ArrayStatic = tuple(ArrayStatic)
print(ArrayStatic)

59
labPython/lab5/Spis22.py Executable file
View File

@@ -0,0 +1,59 @@
def evaluate(expr: str) -> int:
expr = expr.replace(" ", "")
pos = 0
def number():
nonlocal pos
start = pos
if pos < len(expr) and expr[pos] in '+-':
pos += 1
while pos < len(expr) and expr[pos].isdigit():
pos += 1
return int(expr[start:pos])
def factor():
nonlocal pos
if pos < len(expr) and expr[pos] == '(':
pos += 1
result = expression()
if pos >= len(expr) or expr[pos] != ')':
raise ValueError
pos += 1
return result
return number()
def term():
nonlocal pos
result = factor()
while pos < len(expr) and expr[pos] in '*/':
op = expr[pos]
pos += 1
if op == '*':
result *= factor()
else:
num = factor()
if num == 0:
raise ValueError
result //= num
return result
def expression():
nonlocal pos
result = term()
while pos < len(expr) and expr[pos] in '+-':
op = expr[pos]
pos += 1
if op == '+':
result += term()
else:
result -= term()
return result
result = expression()
if pos < len(expr):
raise ValueError
return result
expr = input()
print(evaluate(expr))

Binary file not shown.

Binary file not shown.