题解 | #图形面积#

图形面积

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()


全部评论

相关推荐

10-17 12:16
同济大学 Java
7182oat:快快放弃了然后发给我,然后让我也泡他七天最后再拒掉,狠狠羞辱他一把😋
点赞 评论 收藏
分享
拒绝无效加班的小师弟很中意你:求职意向没有,年龄、课程冗余信息可以删掉,需要提升项目经历。排版需要修改。
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务