日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python turtle怎么用变量_Python Turtle绘图指定变量时出现问题

發布時間:2025/4/17 142 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python turtle怎么用变量_Python Turtle绘图指定变量时出现问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

幾小時后我有一個作業要交,我不知道該做什么。

我使用的是python3。在

我一直試著運行代碼,但是我出錯了。在這一點上,我想我應該尋求幫助。在

提前謝謝你!在import turtle

import random

class myRectangle:

def __var__(self):

self.__x

self.__y

self.__width

self.__height

self.__color

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

self.__x = x

self.__y = y

self.__width = width

self.__height = height

self.__color = color

def getX(self):

return self.__x

def setX(self, x):

self.__x = x

def getY(self):

return self.__y

def setY(self, y):

self.__y = y

def getWidth(self):

return self.__width

def setWidth(self, width):

self.__width = width

def getHeight(self):

return self.__height

def setHeight(self, height):

self.__height = height

def getColor(self):

return self.__color

def setColor(self, color):

self.__color = color

def draw(self, turtle):

turtle.penup()

turtle.goto(self.getX(), self.getY())

turtle.heading(0)

turtle.pencolor("blue")

turtle.pendown()

turtle.begin_fill()

turtle.forward(self.__width())

turtle.left(90)

turtle.forward(self.__height())

turtle.left(90)

turtle.forward(self.__width())

turtle.left(90)

turtle.forward(self.__height())

turtle.left(90)

turtle.end_fill()

def main():

wn = turtle.TurtleScreen

mr = myRectangle

phil = turtle.Turtle()

macie = turtle.Turtle()

sashi = turtle.Turtle()

roxie = turtle.Turtle()

darla = turtle.Turtle()

sammy = turtle.Turtle()

phil.pencolor("blue")

phil.pensize(7)

listofcolors = ("blue", "red", "yellow", "orange", "pink", "green")

c = random.choice(listofcolors)

xy = random.randrange(-200, 201)

wh = random.randrange(1, 151)

for i in [phil, macie, sashi, roxie, darla, sammy]:

mr.setColor(c)

mr.setX(xy)

mr.setY(xy)

mr.setWidth(wh)

mr.setHeight(wh)

main()

錯誤:

^{pr2}$

總結

以上是生活随笔為你收集整理的python turtle怎么用变量_Python Turtle绘图指定变量时出现问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。