GeorgiLukanov87

the magic number nested loops

Apr 8th, 2022 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. start = int(input())
  2. end = int(input())
  3.  
  4. first_start = int(start / 1000)
  5. second_start = int((start / 100) % 10)
  6. third_start = int((start / 10) % 10)
  7. fourth_start = int(start % 10)
  8.  
  9. first_end = int(end / 1000)
  10. second_end = int((end / 100) % 10)
  11. third_end = int((end / 10) % 10)
  12. fourth_end = int(end % 10)
  13.  
  14. for num_1 in range(first_start, first_end + 1):
  15.     for num_2 in range(second_start, second_end + 1):
  16.         for num_3 in range(third_start, third_end + 1):
  17.             for num_4 in range(fourth_start, fourth_end + 1):
  18.                 if num_1 % 2 != 0 and num_2 % 2 != 0 and num_3 % 2 != 0 and num_4 % 2 != 0:
  19.                     print(f'{num_1}{num_2}{num_3}{num_4}', end=' ')
  20.  
Add Comment
Please, Sign In to add comment