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

Someone can help me? What is wrong with my solution?

What is wrong with my code? Someone can help me? Thanks!

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(p):
  palavra_lista = list(p)
  l=int(len(palavra_lista))
  c=l/2
  c=int(c)

  priparte=palavra_lista[:c]
  pri.join(priparte)
  pri=pri.upper()

  segparte=palavra_lista[c:]
  seg.join(segparte)
  seg=seg.lower()

  fim=pri+seg
  return fim

2 Answers

andi mitre
STAFF
andi mitre
Treehouse Guest Teacher

Hey Tulio, I have added comments to your code to explain. Please see below. Also you don't have to turn 'p' into a list.

def sillycase(p):
  palavra_lista = p
  l=int(len(palavra_lista))
  c=round(l/2)
  #c=int(c) not necessary you can use round()

  priparte=palavra_lista[:c]
  # pri.join(priparte) cannot call pri before initializing it
  #pri=pri.upper() 

  segparte=palavra_lista[c:]
  #seg.join(segparte) cannot call seg before initializing it
  #seg=seg.lower() 

  fim= priparte.lower() + segparte.upper()
  return fim

Cheers, Andi

You cannot use a fraction as a slice element. Assigning c to 1/2 does not work, because you can not do this : "string"(1/2: ) -- both sides must refer to integer values. And casting 1/2 as an int returns 0.