Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,932 questions

51,869 answers

573 users

How to convert the odd character of string to uppercase and even characters to lowercase in Python

1 Answer

0 votes
def convert_uppercase_lowercase(s): 
   tmp = "" 
   for i in range(len(s)): 
       if i % 2 == 0: 
          tmp = tmp + s[i].lower() 
       else: 
          tmp = tmp + s[i].upper() 

   return tmp


s = "python java php django"

s = convert_uppercase_lowercase(s)
  
print(s)




'''
run:
 
pYtHoN JaVa pHp dJaNgO

'''

 



answered Feb 12, 2020 by avibootz
...