会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132477个问题

import turtle

a=input("请输入一个x:")
b=input("请输入一个y:")
c=input("请输入一个width:")
d=input("请输入一个height:")

class MyRectangle:

    def __init__(self,x,y,width,height):


        self.x=x
        self.y=y
        self.width=width
        self.height=height

        if self.x=="":
            self.x=0

        if self.x!="":
            self.x=float(x)

        if self.y=="":
            self.y=0

        if self.y!="":
            self.y=float(y)

        if self.width == "":
            self.width = 100

        if self.width!="":
            self.width=float(width)

        if self.height == "":
            self.height = 100

        if self.height!="":
            self.height=float(height)

    def getArea(self):
        return self.width*self.height

    def getPerimeter(self):
        return 2*(self.height+self.width)

    def draw(self):
        turtle.color("red")
        turtle.penup()
        turtle.goto(self.x,self.y)
        turtle.pendown()
        turtle.right(90)
        turtle.forward(self.width)
        turtle.right(90)
        turtle.forward(self.height)
        turtle.right(90)
        turtle.forward(self.width)
        turtle.right(90)
        turtle.forward(self.height)
        turtle.done



m1=MyRectangle(a,b,c,d)
print(m1.getArea())
print(m1.getPerimeter())
m1.draw()

老师,为什么我在调用draw方法的之后海龟作图不显示?

Python 全系列/第一阶段:Python入门/面向对象 1846楼
Python 全系列/第一阶段:Python入门/Python入门(动画版) 1849楼
Python 全系列/第一阶段:Python入门/控制语句 1850楼
Python 全系列/第一阶段:Python入门/函数和内存分析 1854楼
Python 全系列/第一阶段:Python入门/面向对象 1857楼

图片.png

Python 全系列/第一阶段:Python入门/函数和内存分析 1858楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637