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

Luke Telford
Luke Telford
2,931 Points

how do i round letter to be capital or lowercase?

Hello,

I'm doing this challenge and I don't have a clue how to change the case of a letter using the round() function it suggests. I've tried to use dir(round) to see if that helps and also using the online documentation but no luck. i though 'round(text[0:4])' would round the first 5 digits but it doesn't

1 Answer

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hello, Luke Telford

The general idea here is that we wanna divide the length of the String argument by 2, then use that number to slice the String into half, upcase the first half, downcase the 2nd half, then combine them back together, that's the return result of the function.

However, the length of the String can be odd number, divide an odd number by 2 will result in floating point number, and it's illegal to slice String using floating point. That's why you need to use round() method to round the division result to an integer.

round(len(String) / 2)

that's how you use the round() method here, I'll leave it to you to figure out the rest. Feel free to ask if you have more questions.

Luke Telford
Luke Telford
2,931 Points

ahh now i understand, the wording of the question confused me, thank you!