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"

Ian Nazareno
PLUS
Ian Nazareno
Courses Plus Student 1,253 Points

Stuck on the Function challenge task. I think I have the first two lines of code correct, but can't seem to complete it.

I'm just a beginner so pardon all the questions. Here's the challenge and what I have so far: "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."

''' def printer(count): if count = int(input) print("Hi ")

''' I'm stuck in the middle and can't get the correct code for multiplying a string by an integer.

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

3 Answers

Hi, there

The first thing to note is when you write an if function, it should always have : in it at the end! Also the code inside the if function must be indented as well!

Second, this task is much simpler than you think. Like the hint said, you can multiply string with an integer. So print("string" * count) is going to give you "string" printed count times

Kyle Salisbury
seal-mask
.a{fill-rule:evenodd;}techdegree
Kyle Salisbury
Full Stack JavaScript Techdegree Student 16,363 Points

I think you are over thinking this man. This is the code I did and it worked for me. No need to do an "if" statement. Just multiply "Hi " by count and you're set! Welcome to python man, it's my favorite language so far!

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

Ian Nazareno
PLUS
Ian Nazareno
Courses Plus Student 1,253 Points

Hey thanks,

You're right. I'm beginning to realize that I may be over complicating what is asked from these task challenges. Thanks again for the tip!