I need to check for floating point numbers inside my class but it doesn't seem to be working. Any suggestions?
class Rectangle:
def __init__(self, length = 1, width = 1):
self.__length = length
self.__width = width
##Setters to float
def set_length(self, length):
self.__length = float(length)
try:
#self.__length = float(length)
if self.__length > 0.0 and self.__length < 20.0:
print "Value is in range. You may continute."
else:
raise ValueError
except ValueError:
print "Value must be between 0.0 and 20.0"
def set_width(self, width):
self.__width = float(width)
try:
#self.__width = float(width)
if self.__width > 0.0 and self.__width < 20.0:
print "Value is in range. You may continute."
else:
raise ValueError
except ValueError:
print "Value must be between 0.0 and 20.0"
##Getters
def get_length(self):
return self.__length
def get_width(self):
return self.__width
##Get perimeter and area
def perimeter(self):
return 2 * self.__length + 2 * self.__width
def area(self):
return self.__length * self.__width
import rectclass
def main():
## Get length and width
print 'Enter numeric data greater than 0.0 but less than 20.0'
print
a_len = input('Enter Length: ')
print
wide = input('Enter Width: ')
calculations = rectclass.Rectangle(a_len, wide)
print calculations.perimeter()
print
print calculations.area()
main()