Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
vector sum of tuples
#1
"""
Create a function called vector_sum, taking two arguments:
  - Tuple, T1, consisting of multiple float numbers
  - Tuple, T2, of the same length and type as T1

The function must:
  1. Return a tuple, T3 that:
    1.1. Has the same number of elements as T1 and T2
    1.2. Each element in T3 is equal to the sum of the corresponding element in
    T1 and T2
  2. The function documentation should read:
    Return a tuple of the vector sum of numeric sequences
"""
Reply
#2
What is your question? What have you tried?
Reply
#3
I take it this is your homework assignment that you copy pasted.
What is your question ?
Reply
#4
def vector_sum(x,y):
   a = len(x)
   b = len(y)
   if (a == b):
       z = [];
       for i in range(a):
           p = x[i] + y[i]
           z.append(p);
       T3 = tuple(z)
       print T3
   """ for arg in args:
        print arg
    for item in kwargs.items():
        print item"""
x = (1.0,2.0,3.0)
y = (1.0,2.0,3.0)

vector_sum(x,y)
My question is how do i pass in tuples via command line?
Reply
#5
(Nov-28-2016, 09:42 PM)roadrage Wrote: My question is how do i pass in tuples via command line?
You basically can't... but why do you want to? Your assignment doesn't mention the command line. If you really do want to take things in via the command line and use tuples in your code, you can, yourself, create (a) tuple(s) from sys.argv.
Reply
#6
Why would you need to take them in via the command line? That doesn't look like it was part of the problem at all. But if you were determined, sys.argv is your friend.
Reply
#7
2. The function documentation should read:

    Return a tuple of the vector sum of numeric sequences


what should be done for this

what is the difference  between args and kwargs; can i use them in this script for users to give values, if not given then it takes default values?
Reply
#8
(Nov-28-2016, 09:51 PM)roadrage Wrote: 2. The function documentation should read:

    Return a tuple of the vector sum of numeric sequences


what should be done for this
https://www.python.org/dev/peps/pep-0257...docstrings

Quote:what is the difference  between args and kwargs; can i use them in this script for users to give values, if not given then it takes default values?

https://docs.python.org/3/tutorial/contr...ment-lists
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  vector field plots Larssauerkraut 0 1,526 Oct-15-2019, 11:15 AM
Last Post: Larssauerkraut
  Class for Vector no_named_nobody 4 2,591 Oct-06-2019, 03:27 PM
Last Post: no_named_nobody
  Divide a vector Langosmon 1 2,695 May-13-2018, 09:09 AM
Last Post: ThiefOfTime
  Classification by support vector method qwerty 1 2,945 Apr-16-2017, 07:16 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020