Q:

Determine if two inputs are within 10 integers of one another?

I've encountered a problem where I need to find out whether or not two inputs are withing 10 integers of one another however I need the values to be the result of different inputs like so:
value_1 = int(input("Value 1:  "))
value_2 = int(input("Value 2:  "))

However the values may not be identical, this is how far I've come right not however it doesn't work.
val_1 = float(input("Skriv in valfritt värde:   "))
val_2 = float(input("Skriv in valfritt värde:   "))

if val_1 == val_2:
    print("Grattis!")

elif (val_1 - val_2 <= 10) and (val_1 != val_2):
    print("Close but no cigar!")

else:
    print("Not even close!")

(Some of the words the code outputs is written in Swedish.)
However the code works fine as long as val_1 is more than val_2, I'm not sure how to fix it so when val_2 is more than val_1 it still works.
i.e. Now when I input 3.24 as val_1 and 123.6 as val_2, I still get Close but no cigar! even though I want to get Not even close.
I've tried adding another and statement with the opposite symbol (>= 10 instead of <= 10) but it doesn't work.
Code written in python 3.8,

A:

Use the abs function to get the magnitude of the difference:
if val_1 == val_2:
    print("Grattis!")
elif abs(val_1 - val_2) <= 10:
    print("Close but no cigar!")
else:
    print("Not even close!")

This is logically the same as:
if val_1 == val_2:
    print("Grattis!")
elif -10 <= val_1 - val_2 <= 10:
    print("Close but no cigar!")
else:
    print("Not even close!")

but using abs is clearer, I think.

