Skip to content Skip to sidebar Skip to footer

Getting Weird Outputs From My Calculator Program

I have the following code which is a calculator interface: import pygame import operator pygame.init() screen = pygame.display.set_mode((400, 711)) pygame.display.set_caption('INIX

Solution 1:

You get such much 0's because you multiply num1 each while loop with 10:

num1 = num1*10 + int(current)

Even if there are some more problems with your code, start with this:

In the init-section do:

current = -1

Change

    num1 = num1*10+int(current)
    current=

to

    if current>=0:
         num1 = num1*10+int(current)
    current=-1

As I say, there is much more to do. So stay tuned ;)


You should act on pygame.MOUSEBUTTONUP, not on pygame.MOUSEBUTTONDOWN, because "down" has an autorepeat function.

You may safe the target area by the first upcoming DOWN event and ignore further DOWN events until an UP event arrives. You than may check if the DOWN-click-area and the UP-click-area belongs to the same button and only proceed than.

Post a Comment for "Getting Weird Outputs From My Calculator Program"