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 (2015) Logic in Python Fully Functional

Juan Prada
Juan Prada
4,429 Points

print "hi"

so i managed to get this far

def printer (count): print("hi ")

but im not sure what the question is asking

Cheo R
Cheo R
37,150 Points

Hello Juan, you're on the right track.

The prompt is asking to write a function, that when you pass it an argument (a number), your function will print "Hi " that many times. For example

this_many_times = 3

printer(this_man_times)

"Hi Hi Hi"

You're on the right track, all you need to do is to multiply the string by the argument, so your code:

def printer (count): print("hi ")

should be

def printer(count): print("Hi " * count)

this_many_times = 3

printer(this_many_times)

"Hi Hi Hi"

1 Answer

Ryan S
Ryan S
27,276 Points

Hi Juan,

The question is asking you to write a function that takes an argument named "count" and prints the word "Hi " as many times as whatever the "count" variable is equal to.

So if count = 5, it would print Hi Hi Hi Hi Hi.

You can multiply a string by an integer inside a print() function:

def printer(count):
    print("Hi " * count)
Ryan S
Ryan S
27,276 Points

Oh I see Cheo responded while I was typing out my answer! I should've refreshed the page. Anyways, he has a good explanation.