Advertisement
Spocoman

03. Special Numbers

Jan 17th, 2022
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. number = int(input())
  2.  
  3. for i in range(1, number + 1):
  4.     current = str(i)
  5.     sum = 0
  6.     for j in range(len(current)):
  7.         sum += int(current[j])
  8.     is_special = False
  9.     if sum == 5 or sum == 7 or sum == 11:
  10.         is_special = True
  11.     print(f'{i} -> {is_special}')
  12.  
  13.  
  14. Или:
  15.  
  16. for i in range(1, int(input()) + 1):
  17.     current = str(i)
  18.     total = 0
  19.     for j in range(len(current)):
  20.         total += int(current[j])
  21.     print(f'{i} -> {total == 5 or total == 7 or total == 11}')
  22.  
  23. Или:
  24.  
  25. for i in range(1, int(input()) + 1):
  26.     current = i
  27.     total = 0
  28.     while current > 0:
  29.         total += current % 10
  30.         current /= 10
  31.     print(f'{i} -> {total == 5 or total == 7 or total == 11}')
  32.  
  33.  
  34. Тарикатско решение:
  35.  
  36. for i in range(1, int(input()) + 1):
  37.     total = sum([int(i) for i in list(str(i))])
  38.     print(f'{i} -> {total == 5 or total == 7 or total == 11}')
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement