TypeError: expected int, got float

Hi there, I’m new to Python and know a bit of JavaScript, and I want to make a graphing calculator-like application. I tried this code, but floats do not work. How would I get them implemented?
Code:

# import the pygame module, so you can use it
import pygame,sys,os,time,pygame.gfxdraw
 
# define a main function
def main():
     
    # initialize the pygame module
    pygame.init()
    # load and set the logo
    pygame.display.set_caption("minimal program")
     
    # create a surface on screen that has the size of 240 x 180
    screen = pygame.display.set_mode((64,48))
     
    # define a variable to control the main loop
    running = True
    clock=pygame.time.Clock()
    WHITE = (255,255,255)
    BLACK= (0,0,0)
    # main loop
    while running:
        # event handling, gets all event from the event queue
        for event in pygame.event.get():
            
            if event.type == pygame.QUIT:
                # change the value to False, to exit the main loop
                running = False
            startX=0;startY=0;endX=64;endY=48
            clock.tick(24)
            screen.fill(WHITE)
            i = 0
            while (startX+i < 63):
                pygame.gfxdraw.pixel(screen,(startX+i),(startY+(2**i)),BLACK)
                pygame.display.update()
                i = i + 0.5
                time.sleep(0.05)
            time.sleep(3)
            pygame.quit()
            
            
     
# run the main function only if this module is executed as the main script
# (if you import this as a module then nothing is executed)
if __name__=="__main__":
    # call the main function
    main()

Thanks!

-NuLL

You didn’t post the traceback, so I’m going to have to guess where the error is.

I’m guessing that it’s occurring on this line:

pygame.gfxdraw.pixel(screen,(startX+i),(startY+(2**i)),BLACK)

That would be because of this:

i = i + 0.5

i starts as 0, which is an int (integer). Then you add 0.5 to it. 0.5 is a float. From then one, i is a float.

Pixel positions are always integers.

1 Like

me going to ask python.org for help when in reality i’m just dumb