Advertisement
Spocoman

04. Odd and Even Sum

Jan 28th, 2022
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. def result():
  2.     num = input()
  3.     odd_sum = 0
  4.     even_sum = 0
  5.  
  6.     for i in range(0, len(num)):
  7.         if int(num[i]) % 2 == 1:
  8.             odd_sum += int(num[i])
  9.         else:
  10.             even_sum += int(num[i])
  11.  
  12.     return f' Odd sum = {odd_sum}, Even sum = {even_sum}'
  13.  
  14.  
  15. print(result())
  16.  
  17.  
  18.  
  19. Или:
  20.  
  21. def result():
  22.     number = [int(i) for i in list(input())]
  23.     odd_sum = sum([num for num in number if num % 2 == 1])
  24.     even_sum = sum([num for num in number if num % 2 == 0])
  25.  
  26.     return f' Odd sum = {odd_sum}, Even sum = {even_sum}'
  27.  
  28.  
  29. print(result())
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement