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"

Jabari Bellamy
Jabari Bellamy
9,513 Points

How to include a single argument and count inside your function and print "Hi" as many times as count argument?

Does anyone have any ideas on how I can solve this code challenge. Any help would be highly appreciated.

printer.py
def printer(word):
    if word == "Hi":
        print("Hi "*3)

printer("Hi")    

2 Answers

Lukas Coffey
Lukas Coffey
20,382 Points

So the challenge is asking you to print("Hi") as many times as the count argument says. So say if I write this code:

printer(5)
# The output should be:
# HiHiHiHiHi

So, you're taking the string "Hi" and multiplying it by the function argument. You shouldn't need an if: statement. That help?

Jabari Bellamy
Jabari Bellamy
9,513 Points

Ah, I see, thanks mate for offering me your perspective on this code challenge. It makes sense. Thank you.