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 trialPat Dudar
2,490 Pointssillycase.py
I need you to create a new function for me.
This one will be named sillycase and it'll take a single string as an argument.
sillycase should return the same string but the first half should be lowercased and the second half should be uppercased.
For example, with the string "Treehouse", sillycase would return "treeHOUSE".
Don't worry about rounding your halves, but remember that indexes should be integers. You'll want to use the int() function or integer division, //.
def sillycase(string):
#Define uppercase and lowercase integers
#First half lower-cased, second half upper-cased
int string = uppercase_item
int string = lowercase_item
if len(uppercase_item) // 2 == 0:
return item
#uppercase
uppercase =
return item[-2::-2]
else:
return item[-1::-2]
1 Answer
Wade Williams
24,476 PointsYou have a lot going on here, so I think it's best to start over and simplify things. Here's the plan:
- Determine middle index of string
- Lowercase first-half of string
- Uppercase second-half of string
- Put lowercase and uppercase strings together
Now in code
def sillycase(string):
# 1. Middle index is length of string divided by 2
mid_index = len(string) // 2
# 2. Get characters up until Middle index and lowercase them
lower_string = string[:mid_index].lower()
# 3. Get characters starting from Middle index to end of string and uppercase them
upper_string = string[mid_index:].upper()
# 4. Return the lowercase string and uppercase string together
return lower_string + upper_string