Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def manipulate(data):
- if not isinstance(data, list):
- return 'Only list is allowed'
- positive_count = 0
- negative_sum = 0
- for n in data:
- if n > 0:
- positive_count += 1
- elif n < 0:
- negative_sum += n
- return [positive_count, negative_sum]
- # --- tests ---
- tests = [
- # ( data, expected_result )
- ( [1,2,3,4], [4, 0] ),
- ( [1, -9, 2, 3, 4, -5], [4, -14] ),
- ( {}, 'Only list is allowed' ),
- ]
- for data, result in tests:
- print(data, result, manipulate(data) == result)
- # [1, 2, 3, 4] [4, 0] True
- # [1, -9, 2, 3, 4, -5] [4, -14] True
- # {} Only list is allowed True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement