Write some conditions that print True if the variable a is within 10% of the variable b and False otherwise. Compare your implementation with your partner’s: do you get the same answer for all possible pairs of numbers?
There is a built-in function abs
that returns the absolute value of a number:
print(abs(-12))
12
a = 5 b = 5.1 if abs(a - b) <= 0.1 * abs(b): print('True') else: print('False')
print(abs(a - b) <= 0.1 * abs(b))This works because the Booleans ```True``` and ```False``` have string representations which can be printed.