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

helmi al kindy
helmi al kindy
1,371 Points

Can't make it work on my pc

I've already passed this section but when I try to run this code on my computer I get an invalid syntax error.

I use the print command after the function. Eg: print sillycase('hello')

silly.py
# 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(t):
  leng = round(len(t)/2)
  return t[:leng].lower() + t[leng:].upper()
Todd Farr
Todd Farr
9,547 Points

len(t) / 2 will already preform integer division leaving you will a whole number. By adding the round(len(t) / 2) you are actually assigning 2.0 to leng and floating points numbers cannot be used for the string slicing operation. Remove round() and your program will work!

def sillycase(t):
  leng = len(t)/2
  return t[:leng].lower() + t[leng:].upper()

print sillycase("hello")

Hope this helps!

2 Answers

print sillycase("hello")  #not correct
print(sillycase("hello")) #correct for Python 3.x
Todd Farr
Todd Farr
9,547 Points

I guess I should have first asked what version of Python you are using?