Using python 1 Palindrome integer Write the functions with

Using python:

1 ) (Palindrome integer) Write the functions with the following headers:

# Return the reversal of an integer, e.g. reverse(456) returns

# 654

def reverse(number):

# Return true if number is a palindrome

def isPalindrome(number):

Use the reverse function to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.

2) (Math: approximate the square root) There are several techniques for implementing the sqrt function in the math module. One such technique is known as the Babylonian function. It approximates the square root of a number, n, by repeatedly performing a calculation using the following formula:

nextGuess = (lastGuess + (n / lastGuess)) / 2

When nextGuess and lastGuess are almost identical, nextGuess is the approximated square root. The initial guess can be any positive value (e.g., 1). This value will be the starting value for lastGuess. If the difference between nextGuess and lastGuess is less than a very small number, such as 0.0001, you can claim that nextGuess is the approximated square root of n. If not, nextGuess becomes lastGuess and the approximation process continues. Implement the following function that returns the square root of n.

def sqrt(n):

Solution

def reverse(number):
   temp = number
   ans = 0
   while temp>0:
       ans = ans*10 + temp%10
       temp = temp/10
   return ans
def isPalindrome(number):
   if number == reverse(number):
       return True
   else:
       return False
n = int(raw_input(\"Please enter a number:\"))
if isPalindrome(n):
   print(\"The number is a palindrome.\")
else:
   print(\"The number is not a palindrome.\")

Using python: 1 ) (Palindrome integer) Write the functions with the following headers: # Return the reversal of an integer, e.g. reverse(456) returns # 654 def

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site