lmarkov

PB-Python-Nested Loops - Exercise - 02. Equal Sums Even Odd Position

Jun 17th, 2021 (edited)
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.31 KB | None | 0 0
  1. num1 = int(input())
  2. num2 = int(input())
  3.  
  4. for x in range(num1, num2 + 1):
  5.     sum_y = 0
  6.     sum_z = 0
  7.  
  8.     for y in range(0, len(str(x)), 2):
  9.         sum_y += int(str(x)[y])
  10.  
  11.     for z in range(1, len(str(x)), 2):
  12.         sum_z += int(str(x)[z])
  13.  
  14.     if sum_y == sum_z:
  15.         print(f"{x} ", end="")
  16.  
Advertisement
Add Comment
Please, Sign In to add comment