def binaryPallindrome(num):
binary = bin(num)
binary = binary[2:]
return binary == binary[-1::-1]
if __name__ == "__main__":
num = 9
print (binaryPallindrome(num))
Solve Problems by Coding Solutions - A Complete solution for python programming
def binaryPallindrome(num):
binary = bin(num)
binary = binary[2:]
return binary == binary[-1::-1]
if __name__ == "__main__":
num = 9
print (binaryPallindrome(num))
import re
regex = '[a-zA-z0-9]$'
def check(string):
if(re.search(regex, string)):
print("Accept")
else:
print("Discard")
if __name__ == '__main__' :
string = "python@"
check(string)
string = "python326"
check(string)
string = "python."
check(string)
string = "python"
check(string)
def insertionSortRecursive(arr, n):
if n <= 1:
return
insertionSortRecursive(arr, n - 1)
last = arr[n - 1]
j = n - 2
while (j >= 0 and arr[j] > last):
arr[j + 1] = arr[j]
j = j - 1
arr[j + 1] = last
if __name__ == '__main__':
A = [-7, 11, 6, 0, -3, 5, 10, 2]
n = len(A)
insertionSortRecursive(A, n)
print(A)
import math
def digSum( n):
sum = 0
while(n > 0 or sum > 9):
if(n == 0):
n = sum
sum = 0
sum += n % 10
n /= 10
return sum
n = 1234
print (digSum(n))
def hasConsecutiveZeroes(N, K):
z = toK(N, K)
if (check(z)):
print("Yes")
else:
print("No")
def toK(N, K):
w = 1
s = 0
while (N != 0):
r = N % K
N = N//K
s = r * w + s
w = 10
return s
def check(N):
fl = False
while (N != 0):
r = N % 10
N = N//10
if (fl == True and r == 0):
return False
if (r > 0):
fl = False
continue
fl = True
return True
N, K = 15, 8
hasConsecutiveZeroes(N, K)