2

我正在尝试制作一个“绘制”三次和二次图的 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
4

1 回答 1

3

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

你需要做

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

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

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

于 2013-12-04T18:16:26.997 回答