Another alternating-case in-a-string in Python 3.+

后端 未结 3 2033
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 18:17

I\'m very new to Python and am trying to understand how to manipulate strings.

What I want to do is change a string by removing the spaces and alternating the case from

3条回答
  •  逝去的感伤
    2021-01-24 18:28

    You're trying to do everything at once. Don't. Break your program into steps.

    1. Read the string.
    2. Remove the spaces from the string (as @A.Sherif just demonstrated here)
    3. Go over the string character by character. If the character is in an odd position, convert it to uppercase. Otherwise, convert to lowercase.

提交回复
热议问题