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 trialAsad Malgi
641 Pointsi am unable to get this task Write a function named printer. should take a single argument, count, - please help
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.
Please help me with this task. i am stuck since many days with this task and am unable to get it
4 Answers
Asad Malgi
641 Pointsits for python
Jason Manning
417 Pointsdef printer(count): print("hi " * count)
printer(10)
bradleybarron
1,442 PointsThey need some to better translate this stuff. 2nd time a simple wording could solve wasted time.. Ie: Original: 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.
My version: Write a function named printer. Add Count as an argument. Use multiplication to print "Hi" by the Count argument.
This still leaves some room for thought without being too ambiguous.
Tsenko Aleksiev
3,819 PointsIf it's javascript I would use repeat() method:
function printer(count){
console.log("Hi".repeat(count)); //or document.write whatever you want
}
printer(10);
you can do this with a for loop, while loop as well. I don't know what is the task but this works :)
Tsenko Aleksiev
3,819 PointsTsenko Aleksiev
3,819 Pointsthan just do it, I mean:
"Hi" * count
That should do the trick, but I don't know how to write the function in Python :) Add in the course or the language you are using when asking a question please :)