Python Forum
How do classes work? (rectangle)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do classes work? (rectangle)
#3
Thats ok ive managed to figure ropes around this thing
here is the result i came up with seems to work and prety happy with it if there is any improvements im open for sugestions :)

import math

class Rectangle:
    # Init function
    def __init__(self, length, height, Point1x, Point1y, Point4x, Point4y):
        # The only members are length and width
        self.length = length
        self.height = height
        self.Point1x = Point1x
        self.Point1y = Point1y
        self.Point4x = Point4x
        self.Point4y = Point4y
    def findarea(self):
        return self.length * self.height
    def perimeter(self):
        return 2*(self.length+self.height)
    def diagonal(self):
        return (math.sqrt((self.length ** 2) + (self.height ** 2)))
    def center(self):
        return self.length / 2 , self.height / 2
    def Point2(self):
        return self.Point4x - length, self.Point1y - height
    def Point3(self):
        return self.Point1x + length, self.Point4y + height


print('Find area and perimeter of rectangle enter lenght and width values bellow: ')
length=int(input('Please Enter the Length of a Rectangle: '))
height=int(input('Please Enter the Height of a Rectangle: '))
print('Input coordinates of your first point : ')
Point1x=int(input('Please Enter the x coordinate of a Rectangle: '))
Point1y=int(input('Please Enter the y coordinate of a Rectangle: '))
Point4x= Point1x + length
Point4y= Point1y - height


r1=Rectangle(length, height, Point1x, Point1y, Point4x, Point4y)
print('Area : ', r1.findarea())
print('Perimeter : ', r1.perimeter())
print('Diagonal : ', r1.diagonal())
print('Center of Rectangle : ', r1.center())
print ('Top Left corner point coordinates : %.f ' %Point1x,", %.f"%Point1y)
print ('Top Right corner point coordinates : ', r1.Point2())
print ('Botoom Left corner point coordinates : ', r1.Point3())
print ('Botoom Right corner point coordinates : %.f ' %Point4x, " %.f"%Point4y)
Reply


Messages In This Thread
How do classes work? (rectangle) - by GFreenD - Sep-17-2019, 03:41 PM
RE: How do classes work? (rectangle) - by GFreenD - Sep-18-2019, 07:38 PM
RE: How do classes work? (rectangle) - by buran - Sep-18-2019, 07:56 PM
RE: How do classes work? (rectangle) - by GFreenD - Sep-19-2019, 05:44 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020