题解 | #图形面积#

图形面积

http://www.nowcoder.com/practice/cef4036a7bf745d0aeb93e305ba6ead4

比较复杂

import math, cmath
pi = math.pi
class Square(object):
    def __init__(self, line):
        self.line = line
    def Calculated_area(self):
        print(self.line * self.line)
class Rectangle(Square):
    def Calculated_area(self):
        x = self.line.split(" ")
        print(int(x[0])*int(x[1]))
class Circular(Square):
    def Calculated_area(self):
        print("%.3f" % (pi * self.line * self.line))
class Triange(Square):
    def Calculated_area(self):
        p = (self.line*3)/2
        s = (p*(p-self.line)*(p-self.line)*(p-self.line)) ** 0.5
        print("%.3f" % s)
a = input()
if a == "Square":
    S = Square(int(input()))
    S.Calculated_area()
elif a == "Rectangle":
    S = Rectangle(input())
    S.Calculated_area()
elif a == "Circular":
    S = Circular(int(input()))
    S.Calculated_area()
elif a == "Triangle":
    S = Triange(int(input()))
    S.Calculated_area()


全部评论

相关推荐

点赞 评论 收藏
分享
11-18 15:57
门头沟学院 Java
最终归宿是测开:这个重邮的大佬在重邮很有名的,他就喜欢打92的脸,越有人质疑他,他越觉得爽😂
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务