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"

Debdipta Dasgupta
Debdipta Dasgupta
431 Points

How to solve this function

Can't get through this code challenge.Can't understand what the question is asking to do here

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

    printer(5)

2 Answers

TEST_ID = L M_TEST
TEST_ID = L M_TEST
2,238 Points

You have to make a function named printer that takes count as an argument and prints "Hi " as many times as the count argument

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

The challenge is asking you to print "Hi" count number of times.

For example, printer(5) should print "Hi Hi Hi Hi Hi". Your code only prints "Hi " regardless what count you pass in.

You can use a loop like Levan Mebonia suggested or you can use python's * operator.