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"

printer() missing 1 required positional argument: 'count'

Trying to figure out what I'm missing here. The program ran in the workspace but won't run here? Thanks

printer.py
def printer(word, count):
    return(word) * count

print(printer("Hi ",10))

3 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

The challenge says "Write a function named printer. The function should take a single argument, count, and should print 'Hi ' as many times as the count argument."

count should be the only parameter specified:

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

thanks this works in the shell but also keeps returning Bummer! Didn't find the right number of "Hi"s.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

Right. The challenge wants the value printed not returned. Answer updated.

is there anything wrong with my code?

def printer(count):
    if count == '6':
        print(6 * 'Hi\n')

printer("6")
Chris Freeman
Chris Freeman
Treehouse Moderator 68,441 Points

If you're not trying to solve the challenge the code is fine.

While legal code, it will not pass the challenge. It only works for a string value of count. The challenge wants count to be an int. The code also adds a newline char after each "Hi" instead of a space.

Thank you Freeman. I was using that code for the challenge, until I got another way through.