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 trialByron Tollison
9,942 Pointsim struggling really hard with slicing and this exercise
so far i think i have the beginnings of where to go with this function, but i feel like im on the wrong track, can somone help guide me a bit here? im struggling really hard with this one
def sillycase(string):
newstring = int(string) // 2
newstring.upper()
return newstring
1 Answer
Randy Eichelberger
1,491 PointsSo for the challenge you're supposed to return a string that's had the first half .lower() and the second half .upper(). The topic of the recent lessons at this point are all about lists. Most recently deleting and replacing values in a list. The challenges are there to reenforce recent topics.
Break the task down into smaller steps that you have to accomplish. Such as:
# 1. find out where the middle place is. To do this you can use either int() or the integer division operand // # (I prefer to use // over int it's less typing and more easily readable imo)
# 2. convert string to a list where each letter is an individual value in the list.
# 3. set a variable that is lower case and one that is upper case. Then combine the beginning of one string # and the end of the other using the variable you used to store the value gathered from #1. In the videos he used the actual number for the index, but you can substitute that with the variable name above. So like upper_list[:place]
# 4. then after you do this join the list back into an individual string and return that value.
This should get you started at least in the right direction
Byron Tollison
9,942 PointsByron Tollison
9,942 Pointsthanks so much! that makes more sense, i was seriously super lost in even where to start for this one. the only thing tripping me up super bad is how you find the middle of the list without knowing how long the list is. Is this where the division operand comes in handy?
Randy Eichelberger
1,491 PointsRandy Eichelberger
1,491 PointsByron Tollison Yup. So basically we're getting the integer value of the length of the string divided by 2 - len(string) // 2 and we use that to determine the cutoff point for determining where in the upper and where in the lower lists we created to start/stop using slice instead of a specific value within the []. You'd want to assign that to a variable, I called mine place.
We don't care if it's (using the provided example Treehouse) actually 4.5 (9/2 = 4.5). At least in the specific challenge. So we grab the integer value of 4 (because remember integer values of decimals don't round, they just drop anything after the decimal point).
That last paragraph up there is really jumbled I'll try to format it better. There were supposed to be "-" at the beginning of each line. Apparently not. But I've found with any programming task, no matter the size, the best thing to do is to first put in some comments breaking down what you need to do and then working your code in that way. Larger problems like this challenge can get really confusing really really quick. I used to work as a Salesforce.com consultant before deciding to hop over to programming and even then we broke down all of our larger tasks into smaller chunks. It also helps making sure you don't forget anything.
Edit: I just quickly threw it into some code with comments.