`我正在爲終端使用創建個人圖形系統。類去如下:python:終端函數繪圖類中的小邏輯錯誤
import parser
def ev(n, x):
code = parser.expr(n).compile()
return eval(code)
class Graph:
def __init__(self, length, width):
self.l = length
self.w = width
self.graph = [['-' for x in range(self.w)] for x in range(self.l)]
def draw(self):
for i in range(self.l):
temp = []
for j in range(self.w):
temp.append(self.graph[i][j])
print ''.join(temp)
def add(self, f):
y = []
for i in range(self.w):
y.append(ev(f, i))
top = max(y)
bot = min(y)
print y
scale = (top - bot)/self.l
print scale
adj = 0
for i in range(self.l,0,1):
adj = bot + (i * scale)
for j in y:
if j >= adj & j < adj + scale:
self.graph[i][j] = 'X'
所有運行良好,除了該加載模塊,它從一個預定義的函數創建了一個範圍的y值的解析在過去6線的方程,即「X ** 2」代碼,失敗,圖形陣列中沒有點被修改爲「X」
是否有人會這麼好心或許運行和協助,這將是偉大
格式正確的問題,並使用正在使用的編程語言進行標記。 –