Was reading through this blog and found a nice quote “a program a day keeps skill degradation at bay”. I thought that it pretty good advice so I thought to add coding on my blog itself alongwith downloadable content on my github repo.
def reverse_num(num): | |
'''returns the reverse of an integer ''' | |
if num < 0: | |
return - int(str(-num)[::-1]) | |
else: | |
return int(str(num)[::-1]) | |
def is_palindrome(num): | |
'''checks whether a number is palindrome or not''' | |
if str(num) != str(num)[::-1]: | |
return False | |
else: | |
return True | |
def gcd(num1, num2): | |
'''Finding GCD of a number ''' | |
'''IMPLEMENTS Euclid's algorithm for finding GCD''' | |
if num1 == 0 or num2 == 0: | |
return 0 | |
if num1 >= num2: | |
a = num1 | |
b = num2 | |
else: | |
a = num2 | |
b = num1 | |
while b != 0: | |
c = a % b | |
a,b = b,c | |
else: | |
return a |