Here’s what’s wrong with your code:
- You’re using *args which would expand the string you’re passing into the function’s arguments which is not what you want. I’ve replaced it with
arg
. - You’re using
x[n]
instead of simplyx
. When you’re looping through the string, you’re going at it one character at a time. Therefore, simplyx
is sufficient.
In [6]: def Fun_Case(arg):
...: for idx, x in enumerate(arg):
...: if idx%2==0:
...: print(x.upper(), end='')
...: else:
...: print(x.lower(), end='')
...:
...:
...: Fun_Case('python PRogrammING')
Output:
PyThOn pRoGrAmMiNg
7
solved Python Character Casing