Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Collections (Retired) Slices sillyCase

sillycase()

def sillycase(g):
    v = len(g)
    p = v/2
    p = round(p)
  for i in range(len(g)):
      if i < p:
        print(g[i].lower())
      else:
        print(g[i].upper())

sillycase("Treehouse")

This was right from my interpreter but treehouse says it isn't in the python collections last question

[MOD: added ```python markdown formatting -cf]

4 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

In your code you are printing the solution one character at a time to the console. To pass the challenge the function needs to return a single string that is the case-adjusted version of the input.

How would you store the first half of the word as lower(), and the trailing half as upper(), then join the two and return the value?

Hint: you can lowercase to a portion of a word using: first_half = g[:p].lower()

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Also, it looks like there is an indention issue with your if statement.

def sillycase(g):
    v = len(g)
    p = v/2
    p = round(p)
    first = g[:p].lower()

    second = g[p:].upper()
    print(first+second)

sillycase("Treehouse")

in my interpreter it returns kennEth which is correct

but treehouses interpreter returns Error: our function didn't return the right output. Got 'None', expected 'kennETH'.

[MOD added ```python markdown formatting -cf]

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

The reason the code challenge got 'None' is because your function does not have a return statement. Change the print(first+second) to return first+second

That still doesn't explain why None was coming, because print worked fine in my interpreter

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

All statements return something. When a function is called that does not have an explicit return statement, a return None is implied. So your sillycase() function may be printing but the grader is looking at the return value and seeing this default 'None' being returned. The grader does not look at what would be the console output. It instead looks the output of the executed test statements.

Try this in your console:

result = sillycase('Kenneth')
print(result)

The value of result is what the grader checks

so it is because of parsing, lol, i love the way things work, wow you really respond quickly !! :)