I need to take a tuple of any length and preforming an operation to return the midpoint. However, I need to function to work with a tuple of any length so I'm not sure how to go about it.
def findMidpoint(P: tuple, Q: tuple) -> tuple:
user_input1 = input('Enter space-separated integers: ')
P = tuple(int(item) for item in user_input1.split())
user_input2 = input('Enter space-separated integers: ')
Q = tuple(int(item) for item in user_input2.split())
Midpoint
pass
def main():
# use to test the findMidpoint function
pass
if __name__ == "__main__":
main()
Okay, taking some liberties here with what you're asking, but assuming what you want is to find the midpoint of any two points in an N-dimensional space, you can average the value of each point axis-wise. For example:
Obviously, for more dimensions you have to extend this. A general N-dimensional solution, with your code, can make use of zip:
This assumes P and Q are the same length. If they're not, you could go one further and use
zip_longest:This would essentially say "if no coordinate is given for an axis, assume it is zero".