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 trialAndy Hughes
10,049 PointsHow to print "Hi" the right number of times?
I am stuck on the print "Hi" challenge in Python. I have written the code below and tested it in Python Fiddle out it outputs the right number of "Hi's". However, when I copy the code into the challenge window, I get an error. The error says "can't find the right number of Hi's"
Any ideas why it's not passing?
def printer(count):
return("Hi ") * count
print(printer(5))
Edit*****
I think I was over thinking this. For anyone else who gets stuck on this; watching the "exceptions to the rule" video was a great help. It's about one or two videos on from the challenge.
In essence, I was assuming I needed to "return" the value rather than just plain ole "print" it. So if we define the function first and then create the "print" statement i.e. print("Hi " * count), we get the mathematical element plus the print element.
Whilst it works on Python Fiddle if you do it using the return value and then printing the output, the code challenge is very specifically looking for a "print" statement inside the function. Full code below.
def printer(count):
print("Hi " * count)
printer(5)
1 Answer
Steven Parker
231,236 PointsCongratulations on resolving your own issue!
Most challenges involving creating functions will want you to return something. This one is unusual as it asks you to print instead.
I guess the best hint for challenge taking you can get from this is to always read the instructions carefully.
Andy Hughes
10,049 PointsAndy Hughes
10,049 PointsIndeed Steven. 90% of the errors I've had doing these quizzes is down to syntax, spelling or punctuation that doesn't exactly match that in the instructions. PHP Fiddle is much more forgiving! :P