cubic and quadratic graphs?

1k views Asked by At

I am trying to make a pygame program that 'sketches' cubic and quadratic graphs. my code is below. but every time i try running the code i get this error.

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

I don't really know what it means or how to solve it.

sorry if i'm being a pain posting all of my code, i just needed to see if there are any other problems with the code

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
1

There are 1 answers

0
shad0w_wa1k3r On BEST ANSWER

Exactly as the error says, int object is not callable.

You need to do

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

2(5) does not mean 2*5 in python & many other programming languages. You need to specify the multiplication between them.

As for the latter part of the error statement, A(x) means you are calling function A with the argument(s) x.