Logic for this problem can be simplified in the following way. If all letters, of input string $s$, from index $1$ to then end are uppercase, then swap case of all characters and print the result (also, if the string is only length $1$). Otherwise, just print the original string $s$.
You can see the language differences for this kind of problem. C++ is quite terse if you make use of STL functions, Python is also quite short.