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 Print "hi"

Function 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!

printer.py
def printer(count):
  print("{}".format(count)) 

printer("Hi") 

3 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey 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)

:dizzy:

Thank you.!

Eric Fernandez
seal-mask
.a{fill-rule:evenodd;}techdegree
Eric Fernandez
Python Development Techdegree Student 3,008 Points

I 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
Steven Parker
231,271 Points

You 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
Jason Anders
Treehouse Moderator 145,860 Points

Ah... you forget Python's unique (albeit weird) ability to multiply a string by a number to "multi-print." :smiley:

Steven Parker
Steven Parker
231,271 Points

...and I guess David and I both forgot to read the challenge carefully the first time :stuck_out_tongue:

Thank you!