Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. [0,10] <-> a
  2. ]10,77] <-> b
  3. ]77,inf[ <-> c
  4.  
  5. # Bad style
  6.  
  7. provSum=0
  8.  
  9.  
  10. # TRIAL 1: messy if-clauses
  11. for sold in getSelling():
  12. if (sold >=0 & sold <7700):
  13. rate =0.1
  14. else if (sold>=7700 & sold <7700):
  15. #won't even correct mistakes here because it shows how not to do things
  16. rate =0.15
  17. else if (sold>=7700):
  18. rate =0.20
  19.  
  20.  
  21. # TRIAL 2: messy, broke it because it is getting too hard to read
  22. provisions= {"0|2000":0.1, "2000|7700":0.15, "7700|99999999999999":0.20}
  23.  
  24.  
  25. if int(sold) >= int(border.split("|")[0]) & int(sold) < int(border.split("|")[1]):
  26. print sold, rate
  27. provSum = provSum + sold*rate
  28.  
  29. limits = [0, 2000, 7700]
  30. rates = [0.1, 0.15, 0.2]
  31. index = bisect.bisect(limits, sold) - 1
  32. if index >= 0:
  33. rate = rates[index]
  34. else:
  35. # sold is negative
  36.  
  37. if sold >= 7700:
  38. rate = 0.2
  39. elif sold >= 2000:
  40. rate = 0.15
  41. elif sold >= 0:
  42. rate = 0.1
  43. else:
  44. # sold is negative
  45.  
  46. if (sold >=0 & sold <7700):
  47.  
  48. if 0 <= sold < 7700:
  49.  
  50. provisions = {(0, 2000) : 0.1, (2000,7700):0.15, (7700, float("inf")):0.20}
  51.  
  52. # loop though the items and find the first that's in range
  53. for (lower, upper), rate in provisions.iteritems():
  54. if lower <= sold < upper:
  55. break # `rate` remains set after the loop ..
  56.  
  57. # which pretty similar (see comments) to
  58. rate = next(rate for (lower, upper), rate in
  59. provisions.iteritems() if lower <= sold < upper)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement