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"

Yusuf Cattaneo
Yusuf Cattaneo
522 Points

Error

lost

printer.py
def printer():
    print("Hi ")
count()

2 Answers

Gyorgy Andorka
Gyorgy Andorka
13,811 Points

Hi Yusuf!

An argument is a piece of data which a function can take and work with. The arguments which a particular function can take are defined by the parameters (parameter variables) inside the braces after the function name. (A function can have as many parameters as you want, even zero.) In our case, the function should have one parameter, the variable called count, which determines how many times will we print our "Hi " message to the screen. When we use ("call") the function, we'll give an actual value to this variable. This actual data/value assigned to the parameter is the so-called argument. (Thus, the part in the challenge description "should take a single argument, count" should be understood as "should take a single argument, which will be assigned to a parameter variable named count".)

Also note: every line which belongs to the function (the "function body") should be indented - if a line is not indented, then it won't be part of the function definition.

As the challenge says, you can multiply a string by using the * operator, e.g. "Hi " * 2 evaluates to Hi Hi.

# this is the function definition, like a blueprint 
# the function has one parameter, the 'count' variable
# this means that the function can take one argument,
# and any value we're passing in as argument
# will be the new value of this count variable
def printer(count):
    print("Hi " * count)

# now we can use the above defined function like this:
# we're calling the function with a given argument (the integer 3)
# now the value of count will be 3 inside the function,
# so Python will print "Hi " three times
printer(3)  # --> this line will print 'Hi Hi Hi' to the console
Yusuf Cattaneo
Yusuf Cattaneo
522 Points

Thank you for the very detailed explanation :)