Return a string without the first two characters
Yes, some of the things you are doing is redundant and quite messy. As this seems to be a homework assignment I will only provide hints for you here.

What you can do is:


If the string is empty, return an empty string immediately
Store the first character in a variable
Store the second character in a variable, if it exists
Store the rest of the string in a variable, if it exists
Check if the second character is 'b', if it is then add it to the beginning of the string
Check if the first character is 'a', if it is then add it to the beginning of the string
Return the string


A problem of your existing code is that it will fail for strings of length 1. So it is important to only use the first and second characters if they exist at all.