Advertisement
DeaD_EyE

config

Apr 22nd, 2021
931
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. def config(value):
  2.     cols, voltage = divmod(value, 1)
  3.     voltage = round(voltage, 3) * 1000
  4.     for discrete_voltage in range(12, 300, 12):
  5.         if discrete_voltage - 1 <= voltage <= discrete_voltage + 1:
  6.             voltage = discrete_voltage
  7.             break
  8.     else:
  9.         voltage = int(voltage)
  10.     return int(cols), voltage
  11.    
  12.  
  13.  
  14. def test_config():
  15.     values = [2.012, 2.0129, 2.024, 2.0249, 2.0489, 2.0479]
  16.     for val in values:
  17.         print(config(val))
  18.        
  19.  
  20.  
  21. test_config()
  22.  
  23. # (2, 12)
  24. # (2, 12)
  25. # (2, 24)
  26. # (2, 24)
  27. # (2, 48)
  28. # (2, 48)
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement