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 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,276 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,276 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)