Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Logic in Python Print "hi"

functions - problem with assignment

Hi everyone!

im studying functions now and i have some problems with the assignment. the question is:

"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."

the problem im dealing with is that i don't know how to print the "Hi " (print wont work me) - i've tried to run in workspace but there seem to be a problem.

please help me! thanks!

printer.py
def printer(count):
    count=int(input())
    count * 'Hi '

    printer(count)

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,166 Points

You are very close. The command you want is print(). The argument can be the count * 'Hi ':

def printer(count):
    print(count * 'Hi ')

You don't need to use input since the value of your count parameter will be provided by the challenge checker.

Hi! thanks for the answer!

I wrote the code you have provided and it worked. But, there are few things I still don't understand:

  1. Why we didn't use the return()? we want the function to return the value back to us..
  2. why we didn't activated the function at the end (we didn't wrote 'printer(count)' at the end)?
Chris Freeman
Chris Freeman
Treehouse Moderator 68,166 Points

> Why we didn't use the return()? we want the function to return the value back to us..

Yes, return is usually used when a result object needs to be passed back to the calling program. In this case, no object needs returning as the function simply prints values.

If the end of the function code block is reached , a default return None is assumed, which is the same as a lone return.

> why we didn't activated the function at the end (we didn't wrote 'printer(count)' at the end)?

The challenge checker will exercise the code by calling the function with test arguments and compare the output with expected results. This is why challenges ask for a specifically named function so the checker can call it.

Assigning values to function arguments usually causes a conflict with the checker and the challenge to fail.

thanks, you helped me a lot!