Stuck with loops in python - only returning first value

后端 未结 5 1233
情话喂你
情话喂你 2020-12-02 01:16

I am a beginner in Python trying to make a function that will capitalize all of the values with an even index, and make lowercase all of the values with an odd index.

5条回答
  •  长情又很酷
    2020-12-02 01:53

    You are returning after first iteration.

    Try the following:

    def func1(x):
        result = ''
        for (a,b) in enumerate (x):
             if a%2 == 0:
                  result += b.upper()
             else:
                  result += b.lower()
        return result
    

提交回复
热议问题