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 Challenge Problem

Given a non-empty string like "Code" return a string like "CCoCodCode".

string_splosion('Code') → 'CCoCodCode'

string_splosion('abc') → 'aababc'

string_splosion('ab') → 'aab'

def string_splosion(str) :

blank_string = ' '

for letter in str:

    return letter + blank_string

    blank_string += str

2 Answers

Steven Parker
Steven Parker
229,670 Points

Here's some hints:

  • you might want to start with an empty string instead of a space ("blank")
  • return after the loop, not inside it
  • it might work better to add the new blank_string onto itself and then add the next letter

Where is this from? Please provide a link to the course page if this for a Treehouse course.

No it's not from treehouse.

Rogerio de Oliveira
Rogerio de Oliveira
Courses Plus Student 21,319 Points

Hello Mayank!

To solve this problem I used substring (str[:]). Maybe it would be a little bit advanced, but below a solution for your exercise. Keep your good work!

str = raw_input("enter string: ") result = "" for i in range(1, len(str)+1): result += str[0:i] print(result)

Hope it can help you!