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 (2016, retired 2019) Slices sillyCase

Alejandro Byrne
Alejandro Byrne
2,562 Points

I tried my code in workspaces and it worked perfectly. Why not in the challenge?

I copied and pasted my exact code from the console , that worked fine, but it says Try Again! in the error. Why?

sillycase.py
def sillyCase():
    string = input('>>')
    if len(string) % 2 == 0:
        half1 = round(len(string) / 2)
        half2 = round(len(string) / 2)
    else:
        half1 = round((len(string) / 2))
        half2 = round((len(string) / 2))

    print(string[:half1].lower() + string[half2:].upper())

sillyCase()

2 Answers

As Chris said, you should return the new string and not printing it. Second, you seem to be getting user input, but the challenge didn't at all ask for that. Third, your function should take an argument and lowercase that string's first half then uppercase the second half. Finally, you don't need to call the function. Code challenges almost always call functions automatically for you, unless said that it wants you to call it manually.

Keep in mind that code challenges are extremely picky and if you do even one thing the challenge didn't like like for example catching user input for no reason, it won't let you pass. You shouldn't write any code unless the code is what the challenge wants you to! Also, you shouldn't over-think the challenge. Your code may work perfectly in Workspaces, but that doesn't always means that's what the challenge wants you to put into the challenge.

I hope this helps :grin:

~Alex

Alejandro Byrne
Alejandro Byrne
2,562 Points

Oh, dumb mistake. Switched print with return, and it worked. Hate it when I make mistakes like that. My brain just passed right through it... Anyway, I did that and made a few changes:

Changed the name of the function to sillycase.
Switched the input of string to the parameter of the function.
Removed the call of the function at the end.

Thanks for the help - even though thee answers were right under my nose.

Good job :+1:

I didn't even notice that the sillyCase name is wrong. I'm used to camelCase, so I just thought that was okay at first glance :flushed:

Nice catch!

Alejandro Byrne
Alejandro Byrne
2,562 Points

Oh, dumb mistake. Switched print with return, and it worked. Hate it when I make mistakes like that. My brain just passed right through it... Anyway, I did that and made a few changes:

  1. Changed the name of the function to sillycase.
  2. Switched the input of string to the parameter of the function.
  3. Removed the call of the function at the end.

Thanks for the help - even though thee answers were right under my nose.