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"

Emilio Andere
Emilio Andere
495 Points

Python functions

def printer(count): if count() == '5': print("Hi " * count)

count(5)

why is this wrong

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

count(5)

2 Answers

Steven Parker
Steven Parker
231,236 Points

I see a few issues:

  • the instructions only say to write the function (not to also call it)
  • count is not a function and cannot be called by adding parentheses
  • the function should work for any number (not just 5)

I'll bet you can get it now without a code spoiler.

Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

How do you always beat me? Haha! :see_no_evil:

Echo ... Echo ... eccccchhhhho. Lol

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Emilio,

You have all the correct pieces :thumbsup:, but also some that are not asked for, and one not needed and also a bit confusing.

First, the task did not ask you to call the function, so the function call needs to be deleted. With almost all challenges, if you do something that wasn't asked for by the instructions, you will get the Bummer!.

Next, is the if statement. Besides not being ask for or needed, I'm confused as to why you thought it was needed. You are not checking or comparing any values, nor do you need to verify if the parameter equals a certain value. The value passed into the functions parameter can and probably will be different with every call to the function, depending on how many times you want "Hi" printed. So, the if statement checking just for a value of 5... ?

The correct code for the challenge has only two lines:

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

Hope this helps to clear some things up for you. :)
Keep Coding! :dizzy: