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 trialKyle Blaine
3,359 PointsSillycase.py - how to check my code?
Hello all, trying to complete the challenge for sillycase, and here's the code I threw together. I feel like I'm on the right track, but keep getting "BUMMER: Be sure to use integers for indexes. int()
or //
will be needed!"
I guess we haven't really gotten to a "step-by-step debugging" phase, but I'm having trouble passing arguments into the function in workspaces as well. If I call sillycase("string"), I get the error: "TypeError: 'module' object is not callable"
Seeing as the challenge environment is rather vague, I'm not really sure where I'm actually going wrong...
I imagine my mistake is really simple, but a nudge in the right direction will send me miles. Thanks in advance! :)
def sillycase(str):
arg_string = str
length = int(len(arg_string))
silly = arg_string[0:length]
theRest = arg_string[-length:0]
arg_string = str(silly.upper) + str(theRest)
print(arg_string)
Kyle Blaine
3,359 PointsThanks, Tim. I'll check out PyCharm! :)
1 Answer
Alexander Davison
65,469 PointsYou might need to start over from scratch. There are so many little mistakes spread all over the place.
- You are taking in a parameter called
str
, but later you are trying to call it? - What is
arg_string[-length:0]
? - Why are you
print
ing instead of returning? - etc...
Read this other post I wrote a year ago.
Kyle Blaine
3,359 PointsHey Alexander, thanks a ton for referencing that other post, it helped a ton! I think I understand a little better what's actually going on here.
Looking back on the previous code, I think I was thinking that the argument provided would be passed into the function, as opposed to the argument being acted upon by the function.
What is arg_string[-length:0]?
I believe I was trying to slice counting backwards from the length...but now I see, that maybe that's not how it works lol.
I think printing instead of returning was a desperate attempt to debug XD.
Thanks a lot for helping my understanding. I suppose it takes a lot of silly mistakes until something clicks. :)
Tim Buck
5,919 PointsTim Buck
5,919 PointsHi, I don't have time to go through your code but you should check out a program called PyCharm. It is what I use for coding in Python and allows you to run your code and see the output. Will definitely help you see where you're going wrong!