Advertisement
Spocoman

02. Equal Sums Even Odd Position

Dec 30th, 2021 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. start_num = int(input())
  2. final_num = int(input())
  3.  
  4. for num in range(start_num, final_num + 1):
  5.     sum_odd = 0
  6.     sum_even = 0
  7.     digit = num
  8.  
  9.     for n in range(6):
  10.         if n % 2 == 0:
  11.             sum_odd += digit % 10
  12.         else:
  13.             sum_even += digit % 10
  14.         digit //= 10
  15.  
  16.     if sum_odd == sum_even:
  17.         print(num, end=' ')
  18.  
  19.  
  20. РЕШЕНИЕ СЪС STR():
  21.  
  22. start_num = int(input())
  23. final_num = int(input())
  24.  
  25. for num in range(start_num, final_num + 1):
  26.     sum_odd = 0
  27.     sum_even = 0
  28.     current = str(num)
  29.     for n in range(len(current)):
  30.         digit = current[n]
  31.         if n % 2 == 0:
  32.             sum_odd += int(digit)
  33.         else:
  34.             sum_even += int(digit)
  35.    
  36.     if sum_odd == sum_even:
  37.         print(num, end=' ')
  38.  
  39.  
  40. РЕШЕНИЕ С ЛИСТ леко тарикатската:)
  41.  
  42. lst = list(range(int(input()), int(input()) + 1))
  43.  
  44. while len(lst) != 0:
  45.     num = list(map(int, str(lst.pop(0))))
  46.     if sum(num[1::2]) == sum(num[0::2]):
  47.         print(''.join(map(str, num)), end=' ')
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement