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"

Dylan Jackson
PLUS
Dylan Jackson
Courses Plus Student 1,906 Points

Printing a string X number of times

I'm not sure what I'm doing wrong with this Python script, because it works in IDLe. I'm trying to print "Hi " as many times as "count" calls for. The script I'm working with is this:

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

I know count isn't defined in the script, but my understanding is that the grading script should supply it. So, when I set count equal to, say, 4, I get "Hi Hi Hi Hi " which is what I'm being asked for in the question.

printer.py
def printer(count):
    return("Hi ") * int(count)
print(printer(count))

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Dylan,

It seems you went a bit beyond what the challenge is asking for, and challenges do not like it when you do that. The Challenge did not ask for a return statement, so that need to be the print method. It just wants the method to print... nothing else.

Also, when using math functions on a string, you don't use int in front (so no parenthesis around the value either).

So, you pretty much have it. Give it another go with this in mind. (HINT: The answer is only 2 lines of code). Let me know if you're still stuck... but post your new code if you are. :)

Keep Coding! :dizzy: