I'm new to python and this should be a simple function practice exercise.
I wrote this function that should put in upper case every character of a string in which the index is even, but it didn`t work.
When I wrote a very similar (but not as function), it worked. Why?
Code_1:
h = 'abcdefg'
f = ''
for stuff in h:
if h.index(stuff) % 2 == 0:
f = f + stuff.upper()
else:
f = f + stuff.lower()
print(f)
Output: AbCdEfG
Code_2:
h = 'abcdefg'
def func_test(*a):
f = ''
for stuff in a:
if a.index(stuff) % 2 == 0:
f = f + stuff.upper()
else:
f = f + stuff.lower()
return f
func_test(h)
Output: 'ABCDEFG'