Monday, October 17, 2022

[FIXED] How to check if an integer is greater than another by a certain value in python?

Issue

How could I check if the integers in y are greater than x by 2 or more?

For example if I have these variables and want to only return 7 and 10:

x = 3
y = [1,3,4,7,10]


Solution

x = 3
y = [1,3,4,7,10]

out = [] # list to store values

# Make a loop
for v in y:
    if v - x >= 2: # check if greater than x by 2 or more
        out.append(v) # store value


Answered By - Xynias
Answer Checked By - Willingham (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.