I am trying to add the list in the if statement with the number in the elif statement. How do I add them together to get the resulting output?
def sorting(tup1, tup2):
output = []
sumVal = 0
wholeTup = tup1 + tup2
for i in range(0, len(wholeTup)):
if i % 2 == 0 or i == 0:
word = wholeTup[i].title()
output.append(word)
output.sort()
elif i % 2 != 0:
sumVal = sumVal + wholeTup[i]
return output
print(sorting(("Bob",21,"kelly",21), ("morgan",10,"Anna",2)))
The output should look something like:
["Anna", "Bob", "Kelly", "Morgan", 54]
Their names in alphabetical order and all of their ages added together.
I know the if statement will give me this portion of the output:
["Anna", "Bob", "Kelly", "Morgan"]
And the elif statement will give this portion:
54
How can I combine those two together? Is it even possible to combine the output of the if statement and the elif statement?