Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vectors = []
- vectorCounter = -1
- class vector:
- def __init__(self, x, y, z):
- self.x = x
- self.y = y
- self.z = z
- def createVector():
- global vectorCounter
- vectorCounter +=1
- x = int(input('Введите x: '))
- y = int(input('Введите y: '))
- z = int(input('Введите z: '))
- vectors.append(vector(x,y,z))
- def showVectors():
- for i in range(len(vectors)):
- print('Vector{}({}, {}, {})'.format(i,vectors[i].x,vectors[i].y,vectors[i].z))
- def summ(vector1,vector2):
- global vectorCounter
- vectorCounter +=1
- x = vectors[vector1].x + vectors[vector2].x
- y = vectors[vector1].y + vectors[vector2].y
- z = vectors[vector1].z + vectors[vector2].z
- vectors.append(vector(x,y,z))
- print('Полученный вектор: Vector{}({}, {}, {})'.format(vectorCounter,vectors[vectorCounter].x,vectors[vectorCounter].y,vectors[vectorCounter].z))
- def subs(vector1,vector2):
- global vectorCounter
- vectorCounter +=1
- x = vectors[vector1].x - vectors[vector2].x
- y = vectors[vector1].y - vectors[vector2].y
- z = vectors[vector1].z - vectors[vector2].z
- vectors.append(vector(x,y,z))
- print('Полученный вектор: Vector{}({}, {}, {})'.format(vectorCounter,vectors[vectorCounter].x,vectors[vectorCounter].y,vectors[vectorCounter].z))
- def scalar(vector1,vector2):
- result = (vectors[vector1].x * vectors[vector2].x) + (vectors[vector1].y * vectors[vector2].y) + (vectors[vector1].z * vectors[vector2].z)
- return result
- def module(vectorNumber):
- result = ((vectors[vectorNumber].x)**2 + (vectors[vectorNumber].y)**2 + (vectors[vectorNumber].z)**2)**(1/2)
- return result
- def cos(vector1,vector2):
- scal = scalar(vector1,vector2)
- result = scal/(module(vector1) * module(vector2))
- return result
- def menu():
- print('========= Меню =========')
- print('1 - Создать вектор')
- print('2 - Показать все векторы')
- print('3 - Сложение векторов')
- print('4 - Вычитание векторов')
- print('5 - Скалярное произведение векторов')
- print('6 - Длина вектора')
- print('7 - Косинус угла между векторами')
- print('========================')
- key = int(input('Введите номер пункта меню: '))
- if key == 1:
- createVector()
- menu()
- elif key == 2:
- showVectors()
- menu()
- elif key == 3:
- vector1 = int(input('Введите номер первого вектора: '))
- vector2 = int(input('Введите номер второго вектора: '))
- summ(vector1,vector2)
- menu()
- elif key == 4:
- vector1 = int(input('Введите номер первого вектора: '))
- vector2 = int(input('Введите номер второго вектора: '))
- subs(vector1,vector2)
- menu()
- elif key == 5:
- vector1 = int(input('Введите номер первого вектора: '))
- vector2 = int(input('Введите номер второго вектора: '))
- result = scalar(vector1,vector2)
- print('Результат скалярного произведения:', result)
- menu()
- elif key == 6:
- vectorNumber = int(input('Введите номер вектора: '))
- result = module(vectorNumber)
- print('Модуль вектора:', result)
- menu()
- elif key == 7:
- vector1 = int(input('Введите номер первого вектора: '))
- vector2 = int(input('Введите номер второго вектора: '))
- result = round(cos(vector1,vector2), 5)
- print('Косинус угла между векторами:', result)
- menu()
- else:
- menu()
- menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement