문제

Draw a graph with Turtle

import turtle

import random

This is where the code begins

def graph(numX, xWidth, scaleY, radius=2):
    minY = 0
    offsetX = -200
    for xVal in range(numX):

        x = offsetX + (xVal*xWidth)
        rand = random.random()
        y = minY + int(rand*scaleY)
        turtle.penup()
        turtle.goto(x,y)
        turtle.pendown()
        turle.circle(radius)

    graph(20, 20, 100, 5)

    turtle.mainloop()

Should it end like this?

도움이 되었습니까?

해결책

It looks like you have an indentation problem, you are calling the graph function within itself. Try the following:

def graph(numX, xWidth, scaleY, radius=2):
    minY = 0
    offsetX = -200
    for xVal in range(numX):

        x = offsetX + (xVal*xWidth)
        rand = random.random()
        y = minY + int(rand*scaleY)
        turtle.penup()
        turtle.goto(x,y)
        turtle.pendown()
        turle.circle(radius)

graph(20, 20, 100, 5)

turtle.mainloop()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top