Advertisement
sibinasto

4. Functions - Exer - Odd and Even Sum

Feb 6th, 2021
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. def get_odd_even_sum(nums_as_string):
  2.     odd_sum = 0
  3.     even_sum = 0
  4.  
  5.     for char in nums_as_string:
  6.         current_char_as_num = int(char)
  7.         if current_char_as_num % 2 == 0:
  8.             even_sum += current_char_as_num
  9.         else:
  10.             odd_sum += current_char_as_num
  11.     return [odd_sum, even_sum]
  12.  
  13.  
  14. numbers_as_string = input()
  15. result = get_odd_even_sum(numbers_as_string)
  16. print(f'Odd sum = {result[0]}, Even sum = {result[1]}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement