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"

Damian McCarthy
Damian McCarthy
3,656 Points

I'm not getting this one...

Im trying to use the number to keep it true for 5 rotations, then become false. maybe this only makes sense in my head....

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

printer(5)

1 Answer

Dane Parchment
MOD
Dane Parchment
Treehouse Moderator 11,077 Points

Stop for a moment and just look at the code that you have written, then try to reason out the logic in your head.

What you are currently doing is looping while the count variable is true. However, your count variable is a number not a boolean so it cannot equal true.

What you should be doing is checking if the count is greater than 0. That way once you subtract it during each loop once it reaches 0 the loop will exit because the count it no longer greater than 0.

I believe you should be able to code this yourself, but if you are still stuck I can provide the answer for you.

Also I suggest rewatching the videos on comparisons, and variable types because you seem to be having a problem with the currently.

Best of luck and never stop coding!

Damian McCarthy
Damian McCarthy
3,656 Points

I thought that if there was a number than it would be true but as soon as it became zero it became false?

Dane Parchment
Dane Parchment
Treehouse Moderator 11,077 Points

That would work if you did were doing it like so:

def isTrueNum(num):
   if(num):
      print " is true number"
   else:
      print "is false number"

isTrueNum(5)   ; will be true
isTrueNum(0)   ; will be false

Where we are using the number itself as a comparitor.

However, in your case you are trying to see if a number type is equal to a boolean type, which is improper.