Sep-17-2019, 03:41 PM
Hey just wanted to ask if you maybe know how to convert my current code that is below into one that uses classes im kinda confused about it.
it works with pass but im pretty sure its not the way it should be done ive tried with def __init__ but ive lost my self in it.
Im also a bit new to python.
it works with pass but im pretty sure its not the way it should be done ive tried with def __init__ but ive lost my self in it.
Im also a bit new to python.
import math class Rectangle: pass length = float(input('Please Enter the Length of a Rectangle: ')) height = float(input('Please Enter the Height of a Rectangle: ')) # calculate the area Area = length * height # calculate the Perimeter Perimeter = 2 * (length + height) #calculate diagonal of rectangle Diagonal = (length**2) + (height**2) Diagonal = math.sqrt(Diagonal) print(" Diagonal of rectangle: %.4f" %Diagonal) print(" Length of rectangle: %.f" %length) print(" Area of a Rectangle is: %.f" %Area) print(" Perimeter of Rectangle is: %.f" %Perimeter) #points calculation: Point1x = float(input("Enter X coordinates of your first point/corner: ")) Point1y = float(input("Enter Y coordinates of your first point/corner: ")) Point4x = Point1x + length Point4y = Point1y - height Point2x = Point4x - length Point2y = Point1y - height Point3x = Point1x + length Point3y = Point4y + height Centerx = length / 2 Centery = height / 2 print ('Top Left corner point coordinates : %.2f ' %Point1x,", %.2f"%Point1y) print ('Top Right corner point coordinates : %.2f ' %Point2x,", %.2f"%Point2y) print ('Botoom Left corner point coordinates : %.2f ' %Point3x,", %.2f"%Point3y) print ('Botoom Right corner point coordinates : %.2f ' %Point4x,", %.2f"%Point4y) print ('Center point of a rectngle : %.2f ' %Centerx,", %2f"%Centery)