0

I'm trying to scroll through one string and add each character to another string to create a new string.

I have the following function

def rocConvert(self, s):
    newString = ""
    for c in s:
        if c.isupper():
            newString += c
        elif c.islower():
            newString += c
        else:
            newString += c

    return newString

For some reason this is only returning the first char of s. Note, I realize my method is kind of weird for just copying: my end function willl actually be changing the value if it's a lower or upper case character.

Why is this only returning the first character of s?

7
  • I am receiving the entire input string as a return using your unaltered code in Python 2.7.4 console Commented Jul 19, 2013 at 23:12
  • Works fine for me too. python 2.7.5 Commented Jul 19, 2013 at 23:12
  • 3
    Indentation issues in the script maybe? Commented Jul 19, 2013 at 23:13
  • It works for me: ideone.com/yHXaoP Commented Jul 19, 2013 at 23:14
  • 1
    Try running your code using -tt, i.e. python -tt your_program_name.py. Possibly there's a mixed tabs-and-spaces issue, so your return is actually indented inside the for loop, even though it may not look like it. Commented Jul 19, 2013 at 23:14

1 Answer 1

4

Indentation bug. Your return has two tabs in front of it in what you've posted. DSM's -tt suggestion is good.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.