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"

Single Argument function help.

def printer(count): return(count) count = ("Hi! ") * 10 print(count)

I have run the above code through PyCharm and in my terminal. Both have produced "Hi!" ten times as indicated. Treehouse is saying it isnt finding the right number of "Hi"s. What am I doing wrong here?

printer.py
def printer(count):
    return (count)
count = ("Hi ") * 10
print(count)

3 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Zachary Kaufman is correct. It wants the print to happen inside the function. Treehouse is going to send your function a number. It could be 7. It could be 9. It could be 38927. We really don't know. And your code has to print out Hi that many times. Here, you're printing out Hi 10 times which is clearly not the number they're sending in. See the count parameter in the function definition? That's going to hold the number they're going to send in and we can use it just like any other variable. However, you're immediately returning it. Take a look at my solution and see what I mean:

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

Here we accept treehouse's number and it gets assigned to count. Then we take "Hi" and print it out count times. However many that is :smiley: Hope this helps!

Zachary Kaufman
Zachary Kaufman
1,463 Points

don't return count it is possible the grader received count from the return and quit grading

Outstanding! Thank you both! I was just adding too many steps into the code then.

Zachary Kaufman
Zachary Kaufman
1,463 Points

No problem happy to help :) I make mistakes like that all the time

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Derek Gannon You're quite welcome! Yup Zachary Kaufman! I do too. Actually... anyone who has programmed for more than 15 minutes probably has :smiley: