SHARE
TWEET

Untitled

a guest Feb 17th, 2020 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import operator
  2. def get_count(number):
  3.     s = str(number)
  4.     if '.' in s:
  5.         return abs(s.find('.') - len(s)) - 1
  6.     else:
  7.         return 0
  8.    
  9.    
  10. a = 321
  11. b = 78.2
  12. c = 0.145
  13. all_nums = [a,b,c]
  14. dec1 = get_count(a)
  15. dec2 = get_count(b)
  16. dec3 = get_count(c)
  17. dec = [dec1,dec2,dec3]
  18. print(dec)
  19. delta = []
  20. for i in dec:
  21.     delta.append(0.5 * 10**(-i))
  22. least_prec = delta.index(max(delta))
  23. after_rou = [round(i,dec[least_prec] + 1) for i in all_nums]
  24. delta2 = list(map(operator.sub, all_nums, after_rou))
  25. all_sum = sum(after_rou)
  26. all_sum1 = round(all_sum,get_count(all_sum) - 1)
  27. print(all_sum1)
  28. final_delta = all_sum - all_sum1
  29. delta_sum = round(sum(delta) + sum(delta2) + final_delta,2)
  30. print(delta_sum)
  31. rel = delta_sum / all_sum1 * 100
  32. print(rel,"%")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top