Skip to content

Instantly share code, notes, and snippets.

@Pierian-Data
Created March 1, 2018 17:23
Show Gist options
  • Select an option

  • Save Pierian-Data/5767f49f825dbc9f9bf1357b2152b010 to your computer and use it in GitHub Desktop.

Select an option

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)
@Habadej
Copy link

Habadej commented Nov 26, 2024

def myfunc(word):
word_list=[]
i=0
for letter in word:
# print(i)
if i % 2 != 0:
word_list.append(letter.upper())

    elif i % 2 == 0:
        word_list.append(letter.lower())

    i += 1
return ''.join(word_list)

@pritamvijan98
Copy link

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)

@joshi-bhaskar
Copy link

joshi-bhaskar commented Dec 24, 2024

def myfunc(enter_string):
    final_str = []
    for Index in range(len(enter_string)):
        if Index % 2 == 0:
            final_str.append(enter_string[Index].upper())
        else:
            final_str.append(enter_string[Index].lower())
    return ''.join(final_str)
        

@joshi-bhaskar
Copy link

def myfunc(enter_string):
    final_str = ''
    for Index in range(len(enter_string)):
        if Index % 2 == 0:
            final_str = final_str + enter_string[Index].upper()
        else:
            final_str = final_str + enter_string[Index].lower()
    return final_str
        

@leperous
Copy link

leperous commented Jan 7, 2025

def myfunc(string):

final_word = ""

for index, letter in enumerate(string):
if index % 2 == 0:
final_word += letter.lower()
else:
final_word += letter.upper()

return final_word

@andreigh98
Copy link

andreigh98 commented Jan 8, 2025

def myfunc(s):
    mystring = ""
    for a,b in enumerate(s):
        if a % 2 == 0:
            mystring += b.lower()
        else:
            mystring += b.upper()
    return mystring

@sudiptasahu
Copy link

def myfunc(text):
return "".join([letter.lower() if index % 2 == 0 else letter.upper() for index, letter in enumerate(text)])

@sheh420
Copy link

sheh420 commented Jan 14, 2025

def myfunc(a):
b=[]
for letter in a:
if a.index(letter)%2!=0:
x=letter.upper()
b.append(x)
elif a.index(letter)%2==0:
x=letter.lower()
b.append(x)
return ''.join(b)

@xomaralbayati289x
Copy link

def EvenIndexPrinter(ph):
out = []
for i in range(len(ph)):
if i % 2 == 0:
out.append(ph[i].lower())
else:
out.append(ph[i].upper())
print(out)

@Blessy-Mathan
Copy link

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

@shef4793
Copy link

shef4793 commented Feb 28, 2025

def myfunc(string):
    ctr = 0
    while ctr < len(string):
        if ctr%2==0:
            string = string[:ctr] + string[ctr].upper() + string[ctr+1:]
        else:
            string = string[:ctr] + string[ctr].lower() + string[ctr+1:]
        ctr += 1
    return string

@deepak-thakur23
Copy link

def myfunc(mystr):
str1 = ""
strlen = len(mystr)
for ind1 in range(strlen): #index starting from 0
if ind1 % 2 != 0:
str1 = str1+mystr[ind1].upper()
else:
str1 = str1+mystr[ind1].lower()
return str1

strr = "asdfghjkqwerty"
result = myfunc(strr)
print(result)

@bhuvi0209
Copy link

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)
result = myfunc("bhuvaneswari")
print(result)

@Konita98
Copy link

Konita98 commented May 3, 2025

def myfunc(mystr):
i = 0
upstr=mystr.upper()
newstr=""
for i in range(len(mystr)):
if i%2==0:
newstr=newstr+upstr[i]
else:
newstr=newstr+mystr[i]
return(newstr)

@ChanonB
Copy link

ChanonB commented May 16, 2025

def myfunc(w):
myword = []
for letter in range(len(w)):
if letter % 2 == 0:
myword.append(w[letter].upper())
else:
myword.append(w[letter].lower())
return ''.join(myword)

@harishbhatt869
Copy link

harishbhatt869 commented Jun 8, 2025

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

@Srikaranv
Copy link

def myfunc(a):
index=0
max_index=len(a)
out_string=''

while index<max_index:
    aletter=a[index]
    if index%2==0:
        out_string=out_string+aletter.lower()
    else:
        out_string=out_string+aletter.upper()
    index +=1
return out_string

@Srikaranv
Copy link

def myfunc(a):
max_index=len(a)
out_string=''
for letter in range(0,max_index):
aletter=a[letter]
if letter%2==0:
out_string=out_string+aletter.lower()
else:
out_string=out_string+aletter.upper()
return out_string

@Anderson01tw
Copy link

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

print(myfunc("Anderson"))

@Yodeman05
Copy link

def myfunc(c):

       out = []
       for k in range(len(c)):
                 if k%2==0:
                              k.append(c[k].lower())
                 else:
                               k.append(c[k].Upper())

       return ''joint(out)

@Prince181818
Copy link

def myfunc(word):
out = []
for w in range(len(word)):
if w % 2 == 0:
out.append(word[w].upper())
else:
out.append(word[w].lower())

return ''.join(out)

myfunc('prince')

@srhahn
Copy link

srhahn commented Aug 7, 2025

def myfunc(Bob = 'ethnomusicology'):
mylist = [letter for letter in Bob]
Newbob = ''
for x in range(len(mylist)):
if x%2 == 0:
mylist[x] = (mylist[x]).upper()
else:
mylist[x] = (mylist[x]).lower()
Newbob = Newbob + mylist[x]
return Newbob

@pradsham22
Copy link

pradsham22 commented Aug 12, 2025

def myfunc(str):
new_str = ''
i = 0
for char in str:
if i % 2 == 0:
i += 1 # -- coding: latin-1 --
new_str += char.upper()
else:#
new_str += char
i += 1 # -- coding: latin-1 --
return new_str

@hakyeonglee-ds
Copy link

hakyeonglee-ds commented Aug 30, 2025

`def myfunc(word):

alt = ''
indexed_letter = enumerate(word)

for index,letter in indexed_letter:
    if index % 2 == 0:
        alt = alt + letter.lower()
    else:
        alt = alt + letter.upper()

return alt`

@ashok3000
Copy link

Skyline

def myfunc(mystring):
mylist = []
for index in range(len(mystring)):
if index % 2 == 0:
mylist.append(mystring[index].upper())
else:
mylist.append(mystring[index].lower())
return ''.join(mylist)

Output:
myfunc('abcde')
'AbCdE'

@someshvarma015
Copy link

def my fun(x):
out = [ ]
for in range(Len(x)):
if I%2==0:
out.append(x([I].upper())
else:
out.append(x[I].lower())
return ".join(out)

@Arthiar
Copy link

Arthiar commented Oct 9, 2025

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)
print(myfunc("Hello this is Arthi, and I am a student, and I am learning how to work consistently on functions by doing exercises"))

def myfunc(x):
out = []
for word in x.split():
if len(word) % 2 == 0:
out.append(word.lower())
else:
out.append(word.upper())
return ' '.join(out)
print(myfunc("Hello this is Arthi, and I am a student, and I am learning how to work consistently on functions by doing exercises"))

@RahulAmbiger11
Copy link

#10.
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)

res1 = myfunc("Sudeep")
print(res1)

res2 = myfunc("Yash")
print(res2)

@Bjorn-Suerink
Copy link

Bjorn-Suerink commented Nov 6, 2025

def myfunc(s):
num=0
word=''
for letter in s:
if num%2 == 0:
word += letter.lower()
else:
word+= letter.upper()
num+=1
return word
image

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