[Solved] Python Character Casing


Here’s what’s wrong with your code:

  1. 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.
  2. You’re using x[n] instead of simply x. When you’re looping through the string, you’re going at it one character at a time. Therefore, simply x 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