# \[PYTHON\]Converting key pressed into integer value?

**URL:** <https://discourse.processing.org/t/python-converting-key-pressed-into-integer-value/17836>\
**Category:** Processing.py\
**Created:** [February 15, 2020, 9:16am UTC](https://discourse.processing.org/t/python-converting-key-pressed-into-integer-value/17836 "2020-02-15T09:16:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![macedorrn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/macedorrn/32/8097_2.png) [@macedorrn](https://discourse.processing.org/u/macedorrn)\
**Post date:** [February 15, 2020, 9:16am UTC](https://discourse.processing.org/t/python-converting-key-pressed-into-integer-value/17836/1 "2020-02-15T09:16:14Z")

</div>

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.

```auto
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`

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [February 15, 2020, 9:52am UTC](https://discourse.processing.org/t/python-converting-key-pressed-into-integer-value/17836/2 "2020-02-15T09:52:42Z")

</div>

```auto
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))

```

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [February 15, 2020, 10:09am UTC](https://discourse.processing.org/t/python-converting-key-pressed-into-integer-value/17836/3 "2020-02-15T10:09:54Z")

</div>

🐙 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 👌

---

<div class="post-metadata">

**Author:** ![macedorrn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/macedorrn/32/8097_2.png) [@macedorrn](https://discourse.processing.org/u/macedorrn)\
**Post date:** [February 15, 2020, 3:48pm UTC](https://discourse.processing.org/t/python-converting-key-pressed-into-integer-value/17836/4 "2020-02-15T15:48:57Z")

</div>

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