Skip to content

Instantly share code, notes, and snippets.

@banyek

banyek/vector.py

Last active Dec 2, 2017
Embed
What would you like to do?
#!/usr/bin/env python
def scalar(a, b):
acc = 0
for num in range(len(a)):
acc += a[num] * b[num]
return acc
def vectorial(a, b):
c = [None] * 3
c[0] = a[1] * b[2] - a[2] * b[1]
c[1] = a[2] * b[0] - a[0] * b[2]
c[2] = a[0] * b[1] - a[1] * b[0]
return c
def readvector():
read = raw_input()
tokens = read.split(",")
vector = []
for token in tokens:
vector.append(int(token))
return vector
print "Kerem az elso vektort"
v1 = readvector()
print "Kerem a masodik vektort"
v2 = readvector()
if len(v1) == len(v2):
print scalar(v1, v2)
if len(v1) == 3:
print vectorial(v1, v2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment