Question: Define a class Circle, whose objects are initialized with radius as it's attribute.
Ensure that the object creation raises RadiusInputError, a user defined exception, when the input radius is not a number.
Use try ... except clauses.
Create a Circle c1 using the statement c1 = Circle('hello'), and execute the script.
The error message "'hello' is not a number" should be displayed to user.
my code:
class RadiusInputError(Exception):
pass
class Circle:
def __init__(self,radius):
self.radius=radius
if type(self.radius) == "<class 'str'>":
raise RadiusInputError
try:
c1 = Circle('hello')
except RadiusInputError:
print("'Hello' is not a number.")