Lecture Notes on 8 Oct 2012 def recSum (n): if (n == 1): return n else: return recSum (n - 1) + n def sumDigits (n): sum = 0 while (n > 0): sum = sum + (n % 10) n = n // 10 return sum def revNum (n): rev_num = 0 while (n > 0): rev_num = rev_num * 10 + (n % 10) n = n // 10 return rev_num def sumDivisors (n): sum = 0 for divisor in range (1, n // 2 + 1): if (n % divisor == 0): sum = sum + divisor return sum def isPalindromic (num): return (num == revNum(num)) def isPrime (num): limit = int (num ** 0.5) divisor = 2 while (divisor <= limit): if (num % divisor == 0): return False divisor = divisor + 1 return True def main (): ''' num = eval (input ("Enter a number: ")) sum_divisors = sumDivisors (num) print ("Sum of divisors is ", sum_divisors) # print all perfect numbers less than 10000 for num in range (2, 10001): if (num == sumDivisors (num)): print (num) num = eval (input ("Enter a number: ")) rev_num = revNum (num) print (num, rev_num) lo, hi = eval (input ("Enter a range: ")) for n in range (lo, hi + 1): if (isPrime (n)): print (n) for n in range (1000, 10000): if (not isPalindromic (n) and isPalindromic (n * n * n)): print (n) break for n in range (100, 1000): if (isPrime(n) and isPrime (n + revNum(n))): print (n) break ''' for n in range (100, 1000): if (isPrime(n) and not isPalindromic(n) and isPrime(revNum(n))): print (n) main()