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 Fully Functional

Asad Malgi
Asad Malgi
641 Points

i 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
Asad Malgi
641 Points

its for python

Tsenko Aleksiev
Tsenko Aleksiev
3,819 Points

than 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 :)

Jason Manning
Jason Manning
417 Points

def printer(count): print("hi " * count)

printer(10)

bradleybarron
bradleybarron
1,442 Points

They 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
Tsenko Aleksiev
3,819 Points

If 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 :)