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 trialkabirdas
1,976 PointsHow to get function to print multiple times
I'm quite confused on how to get the function to print more than once.'
Here is the challenge question:
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.
help please?
Thank you
def printer(count):
print("{} ".format(count))
count("Hi" * 2)
3 Answers
Alexander Davison
65,469 PointsYou need to do the string multiplication inside the function. It should return something like this:
"Hi" * count
Also, note that you don't need to call the function. The code challenge calls the function automatically. :)
I hope this helps. If you continue to fail, please respond and I'll be happy to help furthermore. I'm not providing the full solution because the best way to learn programming is to try on your own
~Alex
kabirdas
1,976 PointsThank you, I was able to get it. That was much simpler than what I was doing. I thought we had to put an actual integer in.
Alexander Davison
65,469 PointsIf this helped (I believe it did) please provide a Best Answer. Thank you! ~Alex
kabirdas
1,976 PointsThank you. Was there a mistake in this course? The challenge was given before the course. I am now on this lesson and I understand the concept. I'm not sure why they would give the challenge first without covering the material, besides just to test and push our knowledge and logic. Or perhaps it was an accident? None of the other challenges were given before the lessons.
Alexander Davison
65,469 PointsTagging Kenneth Love for this