from math import sqrt #Same but with some memoization, better if you need to check some numbers more than once def prime(x, cache={}): if x not in cache: if x <= 1: cache[x]= False return False for i in range(2,int(sqrt(x))+1): if x % i is 0: cache[x] = False return False cache[x] = True return cache[x]
- from math import sqrt
- #Same but with some memoization, better if you need to check some numbers more than once
- def prime(x, cache={}):
- if x not in cache:
- if x <= 1:
- cache[x]= False
- return False
for i in range(2,int(sqrt(x))):- for i in range(2,int(sqrt(x))+1):
- if x % i is 0:
- cache[x] = False
- return False
- cache[x] = True
- return cache[x]
test.assert_equals(prime(12345),False) test.assert_equals(prime(36),False) test.assert_equals(prime(36),False) test.assert_equals(prime(0), False) test.assert_equals(prime(1), False) test.assert_equals(prime(2), True) test.assert_equals(prime(7), True) test.assert_equals(prime(13), True) test.assert_equals(prime(97), True) test.assert_equals(prime(29), True) test.assert_equals(prime(115249), True) test.assert_equals(prime(4), False)
- test.assert_equals(prime(12345),False)
- test.assert_equals(prime(36),False)
- test.assert_equals(prime(36),False)
- test.assert_equals(prime(0), False)
- test.assert_equals(prime(1), False)
- test.assert_equals(prime(2), True)
- test.assert_equals(prime(7), True)
- test.assert_equals(prime(13), True)
- test.assert_equals(prime(97), True)
- test.assert_equals(prime(29), True)
test.assert_equals(prime(115249), True)- test.assert_equals(prime(115249), True)
- test.assert_equals(prime(4), False)
def decrypt(code,amount): word = "" for i in code: if i==" ": word+=" " continue tmp = ord(i)-amount if tmp<65: tmp+=26 word+=chr(tmp) return word
- def decrypt(code,amount):
#place code herelet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"- word = ""
x=0for c in range(0,len(code)):for i in range (0,len(let)):if code[c] == " ":word+=" "breakelif code[c] == let[i]:x=ix-=amountif x < 0:x+=26word+=let[x]break- for i in code:
- if i==" ":
- word+=" "
- continue
- tmp = ord(i)-amount
- if tmp<65:
- tmp+=26
- word+=chr(tmp)
- return word