简体   繁体   English

如何使用带有海龟图形的Python制作线性图形计算器?

[英]How do I make a linear graphing calculator in Python with turtle graphics?

Why doesn't this code work when I try to graph? 为什么我尝试绘制图形时此代码不起作用? The y-intercept doesn't seem to work. y拦截似乎无效。

from turtle import *

m = float(input("What is the slope? "))

b = float(input("What is the y-intercept? "))

x= window_width()

y= window_height()

y= int(m*x + b)

pd()

goto(x , y)

pd()

goto(-x,-y)

pu()

goto(x/2,0)

pd()

goto(-x/2,0)


pu()

goto(0,2*y)

pd()

goto(0,-2*y)

update()

When I test values with y-intercepts, they go throgh the origin, which means it's not working. 当我用y截距测试值时,它们会绕过原点,这意味着它不起作用。 I'm trying to get the y-intercept working. 我正在尝试进行Y轴拦截。

Why doesn't this code work when I try to graph? 为什么我尝试绘制图形时此代码不起作用?

I see two issues: 1) you seem to be doing things in the wrong order; 我看到两个问题:1)您似乎在以错误的顺序进行操作; 2) you incorrectly assume that if y is f(x) then f(-x) is -y which isn't true: 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()

USAGE 用法

> python3 test.py
What is the slope? 0.5
What is the y-intercept? 100
>

OUTPUT OUTPUT

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Python Turtle 制作线性渐变? - How do I make a linear gradient with Python Turtle? 如何在python龟图形中更改龟的Hitbox大小? - How do I change the Hitbox size of a turtle in python turtle graphics? 如何使用 IDLE 在 python 海龟图形中插入图片? - How do i insert pictures in python turtle graphics using IDLE? 在turtle python中,如何制作hitbox? - In turtle python, how do I make a hitbox? 如何在 HP Prime 图形计算器上运行 Python? - How can I run Python on my HP Prime graphing calculator? 你如何让汽车朝着它所面对的方向移动? (使用 python 和海龟图形) - How do you make a car move in the direction it is facing? (Using python and turtle graphics) 当我想说不止一件事时,如何在 Python 的 Turtle 图形中使用 textinput()? - How do I use textinput() in Turtle graphics for Python when I want to say more than one thing? 如何在 Python Turtle Graphics 中用 RBG 颜色制作彩虹色? - How to make rainbow color with RBG color in Python Turtle Graphics? 如何在 Visual Studio Code 上使用 python 海龟图形绘制递归谢尔宾斯基箭头曲线 - How do I draw recursive Sierpiński arrowhead curve using python turtle graphics on Visual Studio Code Python —将带龟的图形与嵌套列表一起使用。 我该如何解决? - Python — Using turtle graphics with nested lists. How do I solve this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM