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"

Eric Marangu
seal-mask
.a{fill-rule:evenodd;}techdegree
Eric Marangu
Python Web Development Techdegree Student 730 Points

On preview of my code on editor i get 4 "Hi"s as i've defined in my argument. However i don't get the answer right.

I can't seem to get this right. Can someone give me an idea of where i'm going wrong. Thank you.

printer.py
def printer(count):
    count = 4
    print("Hi " * count)

printer("count")

1 Answer

AJ Salmon
AJ Salmon
5,675 Points

Hi Eric,

Your printer function should print "Hi " as many times as the count argument. When Kenneth calls the function, he'll actually put an integer in the argument, not the string "count". In this case, the parameter 'count' is just a placeholder for whatever number is put in its place when the function is called. Here're a few examples of what the output will be:

>>> printer(5)
'Hi '
'Hi '
'Hi '
'Hi '
'Hi '
>>> printer(2)
'Hi '
'Hi '
>>>printer(4)
'Hi '
'Hi '
'Hi '
'Hi '

So, when you use the word count in your function, you're telling python, "Whatever I do to this word, do to whatever number is passed as the argument later on." (And this is because you named the parameter 'count'. You could name it whatever you wanted, and it'd do the same thing. It's just a placeholder that will become whatever number is called with the function.) All that you have to do here is print(count*'Hi ')! Also, you won't need to call the function like you did on line 5, the code challenge engine does that when you select 'check work'. Hope this helps, and happy coding!

AJ