-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7-add_tuple.py
34 lines (24 loc) · 990 Bytes
/
7-add_tuple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/python3
"""
def add_tuple(tuple_a=(), tuple_b=()):
Description:
'add_tuple' function takes two tuples as arguments.
It returns a new tuple where each element is the sum of the elements at the
same index in the input tuples. If an input tuple has less than 2 elements,
it is assumed to be completed with 0s.
Arguments:
"tuple_a" - first tuple of integers
"tuple_b" - second tuple of integers
Return:
Function returns a new tuple with each element being sum of elements
at the same index in the input tuples.
"""
def add_tuple(tuple_a=(), tuple_b=()):
# Define function with two parameters: 'tuple_a' and 'tuple_b'.
a = tuple_a + (0, 0)
# Extend 'tuple_a' with two zeros to ensure it has at least two elements.
b = tuple_b + (0, 0)
# Extend 'tuple_b' with two zeros to ensure it has at least two elements.
return (a[0] + b[0], a[1] + b[1])
# Return a new tuple where each element is the sum of the elements at
# same index in 'a' and 'b'.