pythonは練習図形の計算を継承する

2714 ワード

app.py
app
from sector import Sector
from circle import Circle
from square import Square
while True:
		    print("     
V9.0") print("1.
2.
3. ") print("-"*30) inp = input(" , q :") # if inp == "1": square = Square(" ", 0, 0) # 0 square.say_i() square.sperimeter_area() # elif inp == "2": circle = Circle(" ", 0, 0) circle.say_i() circle.sperimeter_area() # elif inp == "3": sector = Sector(" ", 0, 0) sector.say_i() sector.sperimeter_area() elif inp == "q": break else: print(" , ")

geometry.py
グラフィッククラス
class Geometry():

    def __init__(self,name, perimeter, area):
        self.name = name
        self.perimeter = perimeter
        self.area = area

    #    
    def say_i(self):
        print("-"*30)
        print(self.name)
        print("-" * 30)

    #       
    def sperimeter_area(self):
        print(f"   :{self.perimeter}")
        print(f"   :{self.area}")
        print("-" * 30)

正方形クラス
from  geometry import Geometry
class Square(Geometry):

    #        perimeter, area
    def sperimeter_area(self):
        m = int(input("     :"))
        self.perimeter = 4 * m
        self.area = m**2
        super(Square, self).sperimeter_area()

square.py
正方形クラス
from  geometry import Geometry
class Square(Geometry):
    #        perimeter, area
    def sperimeter_area(self):
        m = int(input("     :"))
        self.perimeter = 4 * m
        self.area = m**2
        super(Square, self).sperimeter_area()

circle.py
円形クラス
from  geometry import Geometry
import math

class Circle(Geometry):

    #        perimeter, area
    def sperimeter_area(self):
        r = int(input("     :"))
        self.perimeter = 2 * r * math.pi
        self.area = r ** 2 * math.pi
        super(Circle, self).sperimeter_area()

sector.py
セクタクラス
from  geometry import Geometry
import math
class Sector(Geometry):

    #        perimeter, area
    def sperimeter_area(self):
        r = int(input("     :"))
        angle = int(input("     :"))

        self.perimeter = 2*r + angle/360*2*r*math.pi
        self.area = angle/360*math.pi*r**2
        super(Sector, self).sperimeter_area()