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"

How do I print count and hi? do I need an if statement?

I need help with this. I don't know what to do. I am completely lost.

printer.py
def printer(count):

print("Hi")


printer(count * "Hi")

3 Answers

Oszkár Fehér
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Oszkár Fehér
Treehouse Project Reviewer

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

you can't multiply an integer with the string just a string with an integer

What do you call count?

The problem is, indentation. Indentation is block in Python.

A variable defined in a block exists only in that block. So for example:

BLOCK1[
variable a;
variable b;
variable c;
# i know a, b and c
]

BLOCK2[
variable x;
variable y;
#I dont know what a, b or c is. But i know what x and y are.
]

The block in python are spearated or defined by indetation.

block1
    in block-one
    in block-one
    still in block-one

not in block-one anymore.

But you already know this.

So the indentation must be kept inn mind.

Another advice is to keep the code only what has asked in question. For example you have called the function and it is not a good idea as there are automated scripts that check your code and anything that it do not understands... it rejects as wrong code.

Lastly, if you multiple the string by a integer... it will repeat it that many time.

Example: print("Hi"*5) will print: 'HiHiHiHiHi'

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


#printer(count * "Hi")

Hope this helps!