Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Logic in Python Print "hi"

andhika pratikto
andhika pratikto
995 Points

print hi

Write a function named printer. The function should take a single argument, count, and should print "Hi " as many times as the count argument. Remember, you can multiply a string by an integer.

which part i did wrong can someone please tell me

printer.py
def printer(count):
    print("Hi ")

printer(2)

1 Answer

Ryan S
Ryan S
27,275 Points

Hi Andhika

You have the printing aspect of the function correct, however you need to use the count variable to multiply the string.

Here is a hint on how string multiplication works:

>>> "Hi " * 3
'Hi Hi Hi'

You don't have to call the function yourself. The code checker will do that for you and pass in its own integer. You just need to handle that integer as the count variable.

Let me know if you need more help.

andhika pratikto
andhika pratikto
995 Points

Thank you! You're awesome!

andhika pratikto
andhika pratikto
995 Points

I thought i got it right but I'm still stuck. Here's what i did

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

Ryan S
Ryan S
27,275 Points

Everything should be inside the function. You don't need to define the count variable yourself.

Also, the multiplication by 3 was only an example to show you how string multiplication works. When your function is tested, you don't know what the integer is going to be. The integer is represented by the "count" variable.

You can multiply the string inside the print function.

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