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"

Marc Casavant
PLUS
Marc Casavant
Courses Plus Student 7,417 Points

Python Basics - Print "hi" - What doesn't this code fulfill from the problem?

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.

-- I'm not sure why code formatting didn't stick but it is correctly formatted in the script with indents.

def printer(count): while (count != 0): print("Hi ") count - 1

What is missing here from the requirement? This should do it.

Marc Casavant
Marc Casavant
Courses Plus Student 7,417 Points

Thanks James, I didn't think of that! I'm also probably a little guilty of rushing through these videos.

I think we're all guilty of that now and then!

2 Answers

count -= 1 is equivalent to count = count - 1 you are decrementing count, but not assigning the "new" value to count to run again.

Think about: print("Hi " * count) avoiding the loop altogether and being more pythonic. (Simple is better than complex.)

Moderator changed from "Comment" to "Answer" so it may be voted on and/or marked as "Best Answer"

Rishabh Verma
Rishabh Verma
2,762 Points

You can do that by :

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

Make sure to not return that function. Because they just asked you to write a function and define value.

Hope it helps you a bit!