Python Python Basics Types and Branching Numeric

walter fernandez
walter fernandez
1,398 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
168,153 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
168,153 Points

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