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

Greg Records
Greg Records
2,060 Points

How do I make a slice upper or lower case

Once again in the Python course the previous video doesn't prepare us on how to handle the upcoming challenge. If the question is going to involve syntax please advise how the syntax will work:

# The first half of the string, rounded with round(), should be lowercased.
# The second half should be uppercased.
# E.g. "Treehouse" should come back as "treeHOUSE"
def sillycase(string):
  first = sillycase[:5].lower()
  second = sillycase[5:].upper()
  both = first + second
  return both

[fixed formatting -cf]

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

Hey Greg, The issue, in this case, is not with the use of the .upper() and .lower(). Your code is assuming a fixed length of variable string and is splitting based on "5" being the midpoint. When the code is submitted for the challenge, multiple test words are used of varying length to check if the function provides a general solution.

The key clue is: "The first half of the string, rounded with round(), should be lowercased.". So instead of using "5", get the length of string, divide by 2, and round() the result:

midpoint = round(len(string)/2)

Using the new midpoint value should give you the results you need. Good Luck!

Ryan Ruscett
Ryan Ruscett
23,309 Points

Hola,

So the trick to these python courses is that after you muddle through the challenge. Within in the the first 1 or 2 minutes of the NEXT video. It shows you exactly how to do what you are trying to do. At least this is what I noticed. But for beginners it's important to make sure the order is proper. haha proper lol

So to make something lower or upper is as simple as this.

>>> lowerCase = "LOWER"
>>> UpperCase = "upper"
>>> print(lowerCase)
LOWER
>>> print(UpperCase)
upper
>>> mkLower =  lowerCase.lower()
>>> mklower
'lower'
>>> upper = UpperCase.upper()
>>> upper
'UPPER'

So if that is confusing... In short, just use two methods.

  1. upper()
  2. lower()

using these two methods are the end of a variable will do what you want. For example

x = "treehouse"
x.upper()
TREEHOUSE

y = "TREEHOUSE"
y.lower()
treehouse

Does this make sense. Please let me know if it does or doesn't or if I missed the mark lol.