sikolia

Instructions for split at codewars.com

Jan 22nd, 2017
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. It's tricky keeping track of who is owed what when spending money in a group. Write a function to balance the books.
  2.  
  3. The function should take one parameter: an object/dict with two or more name-value pairs which represent the members of the group and the amount spent by each.
  4. The function should return an object/dict with the same names, showing how much money the members should pay or receive.
  5. Further points:
  6.  
  7. The values should be positive numbers if the person should receive money from the group, negative numbers if they owe money to the group.
  8. If value is a decimal, round to two decimal places.
  9. Translations and comments (and upvotes!) welcome.
  10.  
  11. Example
  12.  
  13. 3 friends go out together: A spends £20, B spends £15, and C spends £10. The function should return an object/dict showing that A should receive £5, B should receive £0, and C should pay £5.
  14.  
  15. group = {
  16. 'A': 20,
  17. 'B': 15,
  18. 'C': 10
  19. }
  20.  
  21. split_the_bill(group) # returns {'A': 5, 'B': 0, 'C': -5}
Advertisement
Add Comment
Please, Sign In to add comment