-
-
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) |
Zarathustra17
commented
Feb 12, 2024
•
def myfuc(word):
word_letter =[ ]
for l in range(len(word)):
if (l+1) % 2==0:
word_letter+=word[l].upper()
else:
word_letter+=word[l].lower()
return word_letter
output:
myfuc('Anthropomorphism')
['a',
'N',
't',
'H',
'r',
'O',
'p',
'O',
'm',
'O',
'r',
'P',
'h',
'I',
's',
'M']
#WORKING CODE.
def myfunc(a):
d=[]
y=0
for i in a:
y= y+1
if y%2 !=0 :
v=i.lower()
d.append(v)
else:
f=i.upper()
d.append(f)
str = ''
for item in d:
str = str + item
return str
a bit different
def myfunc(words):
new_words = ''
for index,letter in enumerate(words,1):
if (index + 1) % 2 == 0:
new_words = new_words + letter.upper()
else:
new_words = new_words + letter.lower()
return new_words
def myfunc(string):
output = ''
for index,letter in enumerate(string):
if index % 2 == 0:
output += letter.upper()
else:
output += letter.lower()
return output
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()
reutn ' '.join(out)
I think this approach is much better than using the len property inside the range
@Pierian-Data
def myfunc(*args):
str = ''
for key,value in enumerate(args[0]):
if key %2 == 0:
str += value.upper()
else:
str += value.lower()
return str
def myfunc(my_string):
output = []
for i,w in enumerate(my_string):
if i % 2 ==0:
output.append(w.upper())
else:
output.append(w.lower())
return ''.join(output)
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('Hoang'))
def myfunc(str):
sum = ""
pos = 0
for i in str:
pos+=1
z = pos-1
if z % 2 ==0:
a = str[z].upper()
else:
a = str[z]
sum += a
return(sum)
def myfunc(string):
newstring=''
for position in range(len(string)):
if position%2==0:
newstring+=string[position].upper()
else:
newstring+=string[position].lower()
return newstrin`
def myfunc(name):
lname=name.upper()
l=list(lname)
for i in range(0,len(lname),2):
l[i]=l[i].lower()
return ''.join(l)
def myfunc(argumento):
lista=''
for index in range (len(argumento)):
if index % 2 == 0:
lista+=argumento[index].lower()
else:
lista+=argumento[index].upper()
return lista
def myfunc(string2):
chars = [char for char in string2]
i = 0
for j in chars:
if i%2 == 0:
chars[i] = j.lower()
i += 1
else:
chars[i] = j.upper()
i += 1
string2 = ''.join(chars)
return string2
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
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
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')
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')
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'))
def myfunc(st):
lst = [char.upper() if index % 2 != 0 else char.lower() for index, char in enumerate(st)]
return ''.join(lst)
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)