SimeonTs

SUPyF2 Functions-Exercise - 04. Odd and Even Sum

Oct 8th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. """
  2. Functions - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1728#3
  4.  
  5. SUPyF2 Functions-Exercise - 04. Odd and Even Sum
  6.  
  7. Problem:
  8. You will receive a single number.
  9. You have to write a function that returns the sum of all even and all odd digits from that number
  10. as a single string like in the examples below.
  11.  
  12. Examples:
  13. Input:                  Output:
  14. 1000435                 Odd sum = 9, Even sum = 4
  15. 3495892137259234        Odd sum = 54, Even sum = 22
  16. """
  17.  
  18.  
  19. def even_and_odd_sum(number):
  20.     odd_digits_list = [int(digit) for digit in number if digit % 2 != 0]
  21.     even_digits_list = [int(digit) for digit in number if digit % 2 == 0]
  22.     return f"Odd sum = {sum(odd_digits_list)}, Even sum = {sum(even_digits_list)}"
  23.  
  24.  
  25. print(even_and_odd_sum([int(digit) for digit in input()]))
Add Comment
Please, Sign In to add comment