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
Yuda Leh
7,618 PointsPython Basics: The Solution8:06
Can someone please explain this snippit of code to me?
if not user > 0 or not user < 11:
print( "That num isn't between 1 and 10." )
break
I understand the rest of the code!
2 Answers
Hanley Chan
27,771 PointsHi Yehuda,
This is a conditional that is used to check and make sure that player_num is a valid number between 1 and 10.
The code in the conditional outputs a message and breaks out of the loop if player_num is either not greater than 0 or if it is not less than 11.
if not player_num > 0 or not player_num < 11:
print("That number isn't between 1 and 10!")
break
Iman Mk
6,223 PointsHi Yehuda,
It's saying that if the number (or in the code that you provided, user) is not greater than 0, or user is not less than zero then break. It is the same as saying if user is less than 0 or greater than 11, break because the number is not in the 1-10 range.
Let me know if you have any questions.
Yuda Leh
7,618 PointsThanks Iman Mk,
That explains it, now I understand it!
Yuda Leh
7,618 PointsYuda Leh
7,618 PointsThanks Hanley Chan,
Helped alot!