为什么当我试图绘制图形时,这段代码不起作用?
我认为有两个问题:1)你似乎做事情的顺序不对;2)你错误地认为如果y是f(x),那么f(-x)是-y,这不是真的:
from turtle import *
m = float(input("What is the slope? "))
b = float(input("What is the y-intercept? "))
x, y = window_width(), window_height()
# Draw Axes
penup()
goto(x / 2, 0)
pendown()
goto(-x / 2, 0)
penup()
goto(0, y / 2)
pendown()
goto(0, -y / 2)
# Plot function
y = int(m * x + b)
penup()
goto(x, y)
x = -x
y = int(m * x + b)
pendown()
goto(x, y)
done()
用法
> python3 test.py
What is the slope? 0.5
What is the y-intercept? 100
>
输出