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 trialsdf fds
283 Pointsfunctions - 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!
def printer(count):
count=int(input())
count * 'Hi '
printer(count)
2 Answers
Chris Freeman
Treehouse Moderator 68,454 PointsYou 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.
sdf fds
283 Pointsthanks, you helped me a lot!
sdf fds
283 Pointssdf fds
283 PointsHi! thanks for the answer!
I wrote the code you have provided and it worked. But, there are few things I still don't understand:
Chris Freeman
Treehouse Moderator 68,454 PointsChris Freeman
Treehouse Moderator 68,454 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 lonereturn
.> 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.