Advertisement
veronikaaa86

02. Equal Sums Even Odd Position

Aug 6th, 2023
1,034
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. first_num = int(input())
  2. second_num = int(input())
  3.  
  4. for i in range(first_num, second_num + 1):
  5.     current_num_str = str(i)
  6.  
  7.     even_sum = 0
  8.     odd_sum = 0
  9.     for j in range(0, len(current_num_str)):
  10.         digit = int(current_num_str[j])
  11.  
  12.         if j % 2 == 0:
  13.             even_sum += digit
  14.         else:
  15.             odd_sum += digit
  16.  
  17.     if even_sum == odd_sum:
  18.         print(current_num_str, end=" ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement