We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defswap_case(s):#print(s[0])x=0#or you can just use swapcase()t=list(s)foriins:if(i.isupper()):# = i.lower()t[x]=(s[x].lower())x=x+1elif(i.islower()):#i = i.upper()t[x]=(s[x].upper())x=x+1else:t[x]=s[x]x=x+1v=''.join(t)returnv
Got the right answer but on submitting the code, it shows wrong answer. Can someone help me with this?
defswap_case(s):modified_string=" "forcharins:iford(char)>65andord(char)<90:new_ascii=int(ord(char))+32new_char=chr(new_ascii)modified_string=modified_string+new_chareliford(char)>97andord(char)<122:new_ascii=int(ord(char))-32new_char=chr(new_ascii)modified_string=modified_string+new_charelse:modified_string=modified_string+charreturnmodified_string# capital characters - 65 to 90# small characters - 97 to 122# H - 72# h - 104# difference is 32if__name__=='__main__':s=input()result=swap_case(s)print(result)
def swap_case(s):
def swap_case(s): word = s.swapcase() return word
Got the right answer but on submitting the code, it shows wrong answer. Can someone help me with this?