Skip to content

Instantly share code, notes, and snippets.

@Pierian-Data
Created March 1, 2018 17:23
Show Gist options
  • Save Pierian-Data/5767f49f825dbc9f9bf1357b2152b010 to your computer and use it in GitHub Desktop.
Save Pierian-Data/5767f49f825dbc9f9bf1357b2152b010 to your computer and use it in GitHub Desktop.
def myfunc(x):
out = []
for i in range(len(x)):
if i%2==0:
out.append(x[i].lower())
else:
out.append(x[i].upper())
return ''.join(out)
@JMakumi
Copy link

JMakumi commented May 9, 2024

def myfunc(str):
converted_str= ''
char_counter = 0
for char in str:
if char_counter%2==0:
converted_str = converted_str+char.lower()
else:
converted_str = converted_str+char.upper()
char_counter += 1
return converted_str

@Avishruti
Copy link

def myfunc(a):
x=''
for index,word in enumerate(a):
if index%2==0:
x =x + word.upper()
else:
x =x+ word.lower()
return x
myfunc('abhishek')

@Avishruti
Copy link

def myfunc(a):
x=[]
for i in range(len(a)):
if i % 2==0:
x.append(a[i].lower())
else:
x.append(a[i].upper())
return ''.join(x)
myfunc('rita')

@jdavid34
Copy link

def myfunc(s):
new_str = ""
for i in range(len(s)):
if i % 2 == 0:
new_str += s[i].upper()
else:
new_str += s[i].lower()
return new_str

print(myfunc('prueba'))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment