Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dot_product(v, u):
- """ (list of num, list of num) -> num
- Returns the dot product of the two vectors v and u.
- Precondition: len(v) == len(u)
- """
- try:
- if v == [] and u == []:
- return 0
- else:
- return v[0]*u[0] + dot_product(v[1:], u[1:])
- except IndexError:
- # the length of the vectors not the same
- print('The length of the vectors is not the same')
- return None
- except TypeError:
- # There is an incorrect type used
- print("Incorrect type!")
- return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement