Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. def is_happy (n):
  2. cnt1 = n%10;
  3. n = n/10;
  4. cnt1 = cnt1 + n%10;
  5. n = n/10;
  6. cnt1 = cnt1 + n%10;
  7. n = n/10;
  8. cnt2 = n%10;
  9. n = n/10;
  10. cnt2 = cnt2 + n%10;
  11. n = n/10;
  12. cnt2 = cnt2 + n;
  13. if cnt1 == cnt2:
  14. return True
  15. else:
  16. return False
  17. n = int(input())
  18. i = 0;
  19. while 1:
  20. if is_happy(n-i):
  21. print(n-i)
  22. exit(0)
  23. if is_happy(n+i):
  24. print(n+i)
  25. exit(0)
  26. i = i + 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement