Advertisement
Guest User

checkio1.py

a guest
May 26th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. def checkio(*args):
  2.     args = sorted(args)
  3.     return args[len(args)-1]-args[0]
  4.  
  5.  
  6.  
  7.  
  8. #These "asserts" using only for self-checking and not necessary for auto-testing
  9. if __name__ == '__main__':
  10.     def almost_equal(checked, correct, significant_digits):
  11.         precision = 0.1 ** significant_digits
  12.         return correct - precision < checked < correct + precision
  13.  
  14.     assert almost_equal(checkio(1, 2, 3), 2, 3), "3-1=2"
  15.     assert almost_equal(checkio(5, -5), 10, 3), "5-(-5)=10"
  16.     assert almost_equal(checkio(10.2, -2.2, 0, 1.1, 0.5), 12.4, 3), "10.2-(-2.2)=12.4"
  17.     assert almost_equal(checkio(), 0, 3), "Empty"
  18.     print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement