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"

Game Sandilya
Game Sandilya
532 Points

Write a function named printer. The function should take a single argument, count, and should print "Hi " as many times

print "Hi"

printer.py
printer()
    count = print "Enter value"
    for i in count
    print Hi

3 Answers

Hi Game,

You're close! I tried something similar when I did this. Remember that for code blocks in python you need a colon and indentation, so you'd need to reformat your for loop if you were going to solve the challenge this way. However, that's not exactly what the challenge wants. If count = 3, the output should be "Hi Hi Hi", which is not what the for loop will do for you.

Instead, try multiplying your string in the print statement:

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

Also, for future posts in the forum please provide a bit more context as to what problem you're trying to solve. Not sure I'd have understood your problem if I hadn't just done it myself.

You need to write it as a function using def. And if you try combining your line "print Hi" with the count line above, you should have it. You shouldn't need the line "count = . . ." to solve it.

Gyan Yadav
Gyan Yadav
458 Points

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