創建一個方法plot(window, expression, color = "black")
來繪製 窗口中的表達式。 這是我做了什麼:窗口中的繪圖函數
from math import *
from graphics import *
win = GraphWin()
def plot(window, expression, color = "black"):
#Evaluates given expression and plots it in "window". Returns the list of all the plotted points.
points = []
#Evalute expression over 1000 different values and for each (x,y) pair plot the point.
for i in range(0, 1001):
try:
x = i/100.0
y = eval(expression)
plot(x,y)
except Exception:
print("For ", x, " the expression is invalid")
return points
所以我想我做錯了什麼。有人能幫我嗎? :)
你爲什麼猜測你做錯了什麼?你有錯誤嗎(提供完整的追溯)?意想不到的產出(提供投入,預期和實際產出)? – jonrsharpe
有什麼不對?錯誤信息 ?意外的行爲? – hivert
似乎你忘了使用你在函數開頭定義的'points'列表? –