Advertisement
aneliabogeva

Sum Adjacent Equal Numbers

Jun 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 KB | None | 0 0
  1. nums = [float(item) for item in input().split(" ")]
  2.  
  3. i = 0
  4. while i != len(nums):
  5. if len(nums) == 1:
  6. break
  7. f = nums[i - 1]
  8. s = nums[i]
  9. if f == s:
  10. nums[i] = f + s
  11. nums.remove(nums[i - 1])
  12. i = 0
  13. i += 1
  14.  
  15. if len(nums) <= 1:
  16. print(nums[0])
  17. else:
  18. print(" ".join(map(str, nums)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement