Last active
December 2, 2017 22:37
-
-
Save banyek/891d557687e4b7b4f99d8bc21c406597 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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