Python Online Compiler
Example: Python Program to Find Area of Rectangle using Class
C
C++
C#
Java
Python
PHP
main.py
STDIN
Run
# Python Program to Find Area of Rectangle using Class class Calculation(): def __init__(self): self.length = 0.0 self.width = 0.0 self.area = 0.0 def main(self): print("Enter the length & width of the rectangle::\n") self.length = float(input()) self.width = float(input()) self.calculateArea() # It will calculate area of the rectangle def calculateArea(self): self.area = self.length * self.width print("\nArea of rectangle = ", self.area, "units") # It will create instance of the StudentData class Calculation = Calculation() Calculation.main()
45 23
Output
Clear
ADVERTISEMENTS