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 Types and Branching Numeric

walter fernandez
walter fernandez
4,992 Points

hello. i need help

I want to write a code that gives me 42 counterexamples ( it print when it is false). I wrote in a paper, |x|>22 or x=0 I want it to print 21,20,...,1,-1,-2...-21 it is in total 42 lists of a number when my program is false. and I don't know how to write it in python.

2 Answers

Steven Parker
Steven Parker
231,275 Points

You're getting a bit ahead of things here. Later courses will show you ways to do what you describe. But one simple one might look like this:

for x in range(22, -22, -1):        # range can be wider, but this is enough
    if not (abs(x) > 22 or x == 0): # "not" is when the criteria are false
       print(x)   

And there's 44 (not just 42) integer values where your criteria are false.

Steven Parker
Steven Parker
231,275 Points

walter fernandez — Glad to help. You can mark a question solved by choosing a "best answer".
Happy coding!