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 trialdfeem
4,660 PointsFunction 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."
I can't seem to figure this one out. Any input will be helpful. Thanks!
def printer(count):
print("{}".format(count))
printer("Hi")
3 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey there,
I think you got a bit off course for this one. You don't need a formatted string, nor do you need to call the function. The challenge just want a function named "printer" that takes one argument "counter" (Which you have done correctly). The second part is to have the function print the string "Hi " (with a space after) however many times (the integer) passed into the function. This is done by multiplying the string by the value passed in. Have a look at the corrected code below. I hope it makes sense. :)
def printer(count):
print("Hi " * count)
Eric Fernandez
Python Development Techdegree Student 3,008 PointsI think I went overboard whit this question
#function
def product(arg1, arg2):
arguments = arg1 * arg2
print(arguments)
return arguments
#feed back from user
arg1 = int(input("Enter Numerical #1: "))
arg2 = int(input("Enter Numerical #2: "))
#function output
product(arg1, arg2)
Steven Parker
231,248 PointsYou don't want to print the count. You want to print "Hi", and do it as many times as the value passed in as count.
You can either use a loop, or as the challenge itself hints, use the multiply (*) operator to expand the string.
Jason Anders
Treehouse Moderator 145,860 PointsAh... you forget Python's unique (albeit weird) ability to multiply a string by a number to "multi-print."
Steven Parker
231,248 Points...and I guess David and I both forgot to read the challenge carefully the first time
dfeem
4,660 PointsThank you!
Eric Fernandez
Python Development Techdegree Student 3,008 PointsEric Fernandez
Python Development Techdegree Student 3,008 Pointshow do you post your python code like that?