Hands-on - Python - DOCTEST
Hands-on - Python - DOCTEST
>>> isPalindrome(121)
True
>>> isPalindrome(344)
False
>>> isPalindrome(-121)
Traceback (most recent call last):
ValueError: x must be positive integer.
>>> isPalindrome("hello")
Traceback (most recent call last):
TypeError: x must be integer.
"""
try:
x = int(x)
temp=x
rev=0
if(x>0):
while(x>0):
dig=x%10
rev=rev*10+dig
x=x//10
if(temp==rev):
return True
else:
return False
elif(x<0):
raise TypeError
else:
raise ValueError
except ValueError:
raise ValueError("x must be positive integer")
except TypeError:
raise TypeError("x must be an integer")
###################################################################################
#######33333
def area(self):
# Define the doctests for area method below
"""
>>> c1 = Circle(2.5)
>>> c1.area()
19.63
"""
# Define the area functionality below
return round(((self.radius ** 2) * math.pi),2)
def circumference(self):
# Define the doctests for circumference method below
"""
>>> c1 = Circle(2.5)
>>> c1.circumference()
15.71
"""
# Define the circumference functionality below
return round((self.radius * 2 * math.pi),2)