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"

not sure how count works

I know the attached code is far from the answer - I've tried a bunch of other answer and can't seem to get this task. This kinda imitates the code from the previous video...ish

I think it is because I don't understand how the count argument works (in general and inside the function) or really how arguments works.

The videos talked about arguments inside the brackets beside the defined function but also talked about them inside the block - like the print argument.

so I'm a little confused - In my workspace, I can make the definition print "Hi " any number of times with this code but it doesn't seem to be the answer that is being asked for.

any help clearing this up would be appreciated. thanks

printer.py
def printer(count):
    return(count)

Hi = "Hi " * printer(6)
print(Hi)

2 Answers

It happens many a times, to me. I try to follow the question line by line.

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.

So lets try it...

Write a function named printer.

def printer():
    #code goes here.

The function should take a single argument, count,

def printer(count):
    #code goes here.

should print "Hi " as many times as the count argument.

def printer(count):
    st=""
    for i in range(count):
        st = st + "Hi"
    return st

Remember, you can multiply a string by an integer.

def printer(count):
    st = count * "Hi"
    return st

So the final answer is,

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

Hope this was helpful.

ahhhhh...thanks so much....this makes so much sense.