Python Python Collections (2016, retired 2019) Slices sillyCase - 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)
Tim Buck
Tim Buck
4,174 Points

Hi, 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!

Thanks, Tim. I'll check out PyCharm! :)

1 Answer

You 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 printing instead of returning?
  • etc...

Read this other post I wrote a year ago.

Hey 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. :)