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"

Hector Carrillo
Hector Carrillo
934 Points

how do i insert a argument for count?

not sure what im supposed to do

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

2 Answers

Vidhya's code does work, but it is a lot of code to print the same thing count times! You had to set up a while loop, decrement count, etc, which can be really confusing when you basically just want to say "Hi " 5 times. Actually, there's a shortcut, and this mean there's less code which is almost always good.

Here's an example of multiplying strings:

Note that I'm in the Python Shell below!

>>> 'a' * 5
'aaaaa'
>>> 'hello' * 3
'hellohellohello
>>> count = 5
>>> 'Hi ' * count
'Hi Hi Hi Hi Hi '

The last example probably sparked your mind. (If it didn't don't worry. If you learn enough, you'll probably be smarter than others!) This is what the challenge is asking for! Print "Hi " count times! Ta-da! :wink:

So, to add this into our work, we can do:

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

I hope this helps. ~Alex

Vidhya Sagar
Vidhya Sagar
1,568 Points

Whenever you go for a function ,arguments means the things you insert in the brackets .So in you're challenge it should be def printer(count). It also specifies that ,it should print Hi as many times as the count variable which is an integer ,so for this a while loop should be perfect .Try it on you're own .I'll also add the code below .

Spoiler Alert

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