Advertisement
furas

Python - digit 7 in numbers 0-100

May 21st, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. result = 0
  2.  
  3. value = 100 # 107, 117, 276
  4. checked = 7
  5.  
  6. # --- first place ---
  7.  
  8. result += (value // 10) * 1
  9. rest = value % 10
  10. if rest >= checked * 1:
  11.     result += 1
  12.  
  13. # --- second place ---
  14.  
  15. result += (value // 100) * 10
  16. rest = value % 100
  17. if rest >= checked * 10:
  18.     result += 1
  19.  
  20. # --- third place ---
  21.  
  22. result += (value // 1000) * 100
  23. rest = value % 1000
  24. if rest >= checked * 100:
  25.     result += 1
  26.  
  27. # --- etc.
  28.  
  29. print('result:', result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement