python - 三次图和二次图?

标签 python graph pygame quadratic cubic

我正在尝试制作一个 pygame 程序来“绘制”三次和二次图。 我的代码如下。但每次我尝试运行代码时都会收到此错误。

y = 250 - ((A(x)**B)+(C(x)**D)+(E(x))+c)
TypeError: 'int' object is not callable

我真的不知道这意味着什么或如何解决它。

抱歉,如果我发布所有代码很麻烦,我只是需要看看代码是否还有其他问题

import pygame,sys,time,random
A =1
B =2
C =5
D =1
E =7
c =5
line = (0,0,0)
x = 0.0
screen = pygame.display.set_mode((500,500))
screen.fill((255,255,255))
draw = True
start = True
count = 0
while start:
    pygame.draw.line(screen,(0,0,0),(250,0),(250,500))
    pygame.draw.line(screen,(0,0,0),(0,250),(500,250))
    while x <=500:
        y = 250 - ((A(x)**B)+(C(x)**D)+(E(x))+c)
        pos = (((x)+250),y)
        pygame.draw.line(screen,(line),(pos),(pos))
        pygame.display.update()
        x +=1
       for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit();sys.quit();

        again = raw_input('again? y/n')
        if again == 'y' or again == 'yes':
            start = True
            screen.fill(255,255,255)
            x = 0.0
        elif again == 'n' or again == 'no':
            start = False

最佳答案

正如错误所述,int 对象不可调用。

你需要做

y = 250 - ((A*(x)**B)+(C*(x**D))+(E*(x))+c)

2(5) 在 python 和许多其他编程语言中并不意味着 2*5。您需要指定它们之间的乘法。

对于错误语句的后半部分,A(x) 表示您正在使用参数调用函数A x

关于python - 三次图和二次图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20382743/

相关文章:

Python:辛普森法则,曲线下正面积的否定答案?

Python 3 : How to add a function to a Python class of a library?

python - 用 Python 编写后更改文件的修改日期

python - 混合整数编程 - 仓库位置 (Python + GLPK)

c - O(n) 中各点的绝对距离

algorithm - 图表数据的想法

graphics - 用于构建动态图表的最佳网络技术

python - 使用y轴(pygame)跳转验证码不起作用

python - Pygame窗口在制作后没有响应

python - 感染效率 - Pygame