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 Basics Functions and Looping Reviewing Functions

Mark Chang
Mark Chang
5,214 Points

Can anyone help me explain this code?

code(or click View Quiz button ) : https://w.trhou.se/fqgl2boxmb

click quiz.py for the code

output:

Puzzle 1:

Puzzle 2:

can anyone help me explain this code, and how the code works?, I don't sure how the code will work, and why there a string called "treehouse" but it didn't appear at the output?

1 Answer

John Lack-Wilson
John Lack-Wilson
8,181 Points

Hey Mark, you need to concentrate on what the display_blanks function is actually doing:

  • It takes a word as an argument
  • It then declares a variable blanks, and assigns it the value of -'s multiplied by the length of the word that was passed to the function
  • Finally it prints out the blanks variable

So lets say we call it and pass it 'mark', i.e. display_blanks("mark"). The first line in the function says multiply '-' by the length of "mark" (which is 4), so now blanks = "----", then complete the function by printing out blanks.

So the only use that the string passed to the function has it to use its length.

Mark Chang
Mark Chang
5,214 Points

Thanks for your answer :) The function is the hardest part for me at beginning, also in javascript

John Lack-Wilson
John Lack-Wilson
8,181 Points

Yeah I understand that - there will be a eureka moment for functions for you. I know there was for me!

Mark Chang
Mark Chang
5,214 Points

yeah function is hard for begnning