0

I want program to change all lower letters to upper and vice versa but if there is same letters it only takes first eg. "Aa" it should change it to "aA", but it gives me "AA" instead "aA", I think because it changes always first letter

S = input()
for item in S:
    if item.islower():
        S = S.replace(item, item.upper())
    elif item.isupper():
        S = S.replace(item, item.lower())
print(S)
  • Also see: [**better way to invert case of string**](https://stackoverflow.com/q/26385823/1164465) – Christopher Peisert Oct 11 '20 at 23:06
  • The issue is `str.islower()` returns true only if all the characters in the string are lowercase, try using it on the actual characters in the underlying string instead: https://repl.it/repls/HumiliatingThirstyVendor#main.py – Sash Sinha Oct 11 '20 at 23:21
  • I know that it is possible to do that another way, but my point is to change cases of existing string without creating another on or another tab – Mateusz Matejko Oct 11 '20 at 23:30

1 Answers1

0

U don't need to call the replace method. Instead let ur code look like this. for item in s: if item.islower(): print(item.upper() end='') else: print (item.lower())

Adeyemi Deji
  • 1
  • 1
  • 2