[PYTHON]Converting key pressed into integer value?

I am trying to convert the value of numeric keys into integers, but I don’t know how to proceed with this problem. I have tried many approaches. What am I doing wrong? I don’t have much knowledge related to programming.

circle_x = 250
circle_y = 250
circle_size = 50
diameter = 50

def calculate_size(diameter, key):
    return diameter ** key

def setup():
    size(500, 500)
    return 

def draw():
    global circle_x, circle_y, circle_size
    background(0, 0, 40)
    ellipse(circle_x,circle_y, circle_size, circle_size)

def mouseClicked():
    global circle_x, circle_y
    circle_x = mouseX
    
    circle_y = mouseY

def keyPressed():
    global circle_size, circle_x, circle_y, diameter
    if key == int(key):
        circle_size(circle_x, circle_y, calculate_size(diameter,key), calculate_size(diameter, key))

Preformatted text

def calculate_size(diameter, key):
    return diameter * key

...
 
def keyPressed():
    global circle_size, circle_x, circle_y, diameter
    if key.isdigit():
        circle_size = calculate_size(diameter, int(key))

:octopus: Please avoid posting the same question in two places.

Also, highlight your code and apply the “preformatted text” option. It looks like a </> button in your post editor. This will retain your indentation and automatically color-highlight different parts of your code :ok_hand:

1 Like

I’m sorry. I tried to delete this post, but it says I can’t. Thank you for help, it worked!