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"

Unsure as to why it "doesn't return the right number of Hi's" If I run the same code in Workspaces it runs perfectly.

Why is my answer not accepted?

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

hi = printer(5)

print(hi)

2 Answers

Michael Hulet
Michael Hulet
47,912 Points

You definitely have the right idea here. In fact, when I did the challenge myself to test, I made the same mistake. The challenge asks you to print all the "Hi "s, not return them. If you change the return to a call to print, I believe you'll pass the challenge. It also might be a good idea to remove all the code except the function you made, because I know Treehouse challenges can be a little finicky like that sometimes

Thanks Mike, you're right. I guess I was thinking back to the tutorial that the challenge immediately follows, where it teaches return.

I was conscious that the challenge wanted to print the Hi's which is why after assigning the function to the variable, I printed them! I guess Treehouse wants to be very particular! You helped a lot though, thanks :)

Michael Hulet
Michael Hulet
47,912 Points

No problem! You have to pay pretty close attention to these challenges a lot of times. It's really easy to overlook something like that. I do it all the time, too