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 trialJosh Haefner
2,124 PointsWhy wont my code work?
def printer(count): while count > 0: count -= 1 print "Hi"
printer(2)
The instructions are to print "Hi" as many times as the value of the count argument. I run the program in repel.it and it works just fine. However, it will not let me pass the challenge to move on.
2 Answers
Steven Parker
231,275 PointsYou're testing with an old version of Python.
In version 3 (as used in the course), "print()" is a function and the argument must be enclosed in parentheses.
Also, be aware the the instructions only ask that you create the function, not to also invoke it.
AJ Salmon
5,675 PointsHey Josh,
The print() function needs to have parentheses immediately following it, enclosing the object you wish to print. Ex.:
print('Hi')
Nice idea decrementing count by one every time you print Hi! Another way to solve it would be like this:
def printer(count):
print('Hi' * count)
Neither way is necessarily better. It shows that you grasp while loops, which is a very good thing. Happy coding :)