Jul-24-2018, 04:44 AM
The question wants me to create a function that takes a tuple as an input, and returns a new tuple as an output, where every other element of the input tuple is copied, starting with the first element.
actual output: typeError: can only concatenate tuple (not "int") to tuple
I'm confused about the basis of the question because I learned a tuple is immutable so how could I do this?
def oddTuples(aTup): i=0 what_I_want=() while i<len(aTup): if i%2==0: final=final + aTup[i] i+=1 print(what_I_want) oddTuples((1, 2, 3, 4 ,5,))expected output: (1, 3, 5)
actual output: typeError: can only concatenate tuple (not "int") to tuple
I'm confused about the basis of the question because I learned a tuple is immutable so how could I do this?