__author__ = 'Jacob Gilliam' import math def square(x): return int(x) * int(x) def sumOfList(x): return sum(map(square, list(str(x)))) def liststuff(x): seen_numbers = set() while x > 1 and (x not in seen_numbers): seen_numbers.add(x) x = sumOfList(x) return x == 1 def check(x): if x == 1: return True elif x == 4: return False else: return liststuff(sumOfList(x)) def isFib(n): phi = 0.5 + 0.5 * math.sqrt(5.0) a = phi * n return n == 0 or abs(round(a) - a) < 1.0 / n def isPalindrome(x): if (x < 0): return False div = 1 while (x / div >= 10): div *= 10 while (x != 0): l = x / div r = x % 10 if (l != r): return False x = (x % div) / 10 div /= 100 return True; #method to check to see if the number is prime def is_prime(n): if n % 2 == 0 and n > 2: return False return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2)) in1 = raw_input("Please enter a number to see if Mr. Lemont likes it!") if is_prime(int(in1)): print("Mr. Lemont Likes The Number: " + str(in1)) else: if isPalindrome(int(in1)): print("Mr. Lemont Likes The Number: " + str(in1)) else: if isFib(int(in1)): print("Mr. Lemont Likes The Number: " + str(in1)) else: if check(int(in1)): print("Mr. Lemont Likes The Number: " + str(in1)) else: print("Mr. Lemont Does Not Like The Number: " + str(in1))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question