#๐Ÿ”’ Making two circles in grid

20 messages ยท Page 1 of 1 (latest)

indigo linden
#

Hey, I already asked this but I didn't have time to fix this issue then and my post got closed. So my issue is that I want two filled circles next to each other, but I'm a bit lost on how to do it. I got some help with the grid size, but I'm not sure if I did it right. Here's what I did so far:

import math

def balls(radius):

    # empty grid
    grid = [[' ' for y in range(radius * 2)] for x in range(radius * 4)]

    for y in range(radius * 2):
        for x in range(radius * 2):
            centre = (x - radius) ** 2 + (y - radius) ** 2
            if radius >= centre:
                grid[y][x] = 'x'

    print(grid)

radius = int(input("Choose your size: "))
balls(radius)`


I also attached the output

My mistake before was that I made the grid radius x radius

Thanks!!
unreal lanternBOT
#

@indigo linden

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

timid quarry
#

Using math.dist may help to condense your code a little.

#

!d math.dist

unreal lanternBOT
#

math.dist(p, q)```
Return the Euclidean distance between two points *p* and *q*, each given as a sequence (or iterable) of coordinates. The two points must have the same dimension.

Roughly equivalent to:

```py
sqrt(sum((px - qx) ** 2.0 for px, qx in zip(p, q)))
```   Added in version 3.8.
timid quarry
#

As may the complex type.

#

!d complex

unreal lanternBOT
#

class complex(number=0, /)``````py

class complex(string, /)``````py

class complex(real=0, imag=0)```
Convert a single string or number to a complex number, or create a complex number from real and imaginary parts.

Examples...
timid quarry
#

!d abs

unreal lanternBOT
#
abs

abs(x)```
Return the absolute value of a number. The argument may be an integer, a floating point number, or an object implementing [`__abs__()`](https://docs.python.org/3/reference/datamodel.html#object.__abs__). If the argument is a complex number, its magnitude is returned.
timid quarry
#

!e py import math p = 0, 0 q = 1, 1 result = math.dist(p, q) print(result)

unreal lanternBOT
timid quarry
#

The distance between 0, 0 and 1, 1.

#

!e py q = complex(1, 1) result = abs(q) print(result)

unreal lanternBOT
untold zenith
timid quarry
#

If you don't want to use imports, I guess.

indigo linden
#

Is it possible to do it similarly how I started making it? I'm a beginner and I feel like I'd understand it better this way

unreal lanternBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.