Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_happy (n):
- cnt1 = n%10;
- n = n/10;
- cnt1 = cnt1 + n%10;
- n = n/10;
- cnt1 = cnt1 + n%10;
- n = n/10;
- cnt2 = n%10;
- n = n/10;
- cnt2 = cnt2 + n%10;
- n = n/10;
- cnt2 = cnt2 + n;
- if cnt1 == cnt2:
- return True
- else:
- return False
- n = int(input())
- i = 0;
- while 1:
- if is_happy(n-i):
- print(n-i)
- exit(0)
- if is_happy(n+i):
- print(n+i)
- exit(0)
- i = i + 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement