#๐Ÿ”’ Empty grid looping forever

7 messages ยท Page 1 of 1 (latest)

golden scaffold
#

Hi! I'm trying to make two circles next to each other, but I got some issues. Someone recommended me to try a code visualizer, and it helped me understanding things more! However, I still don't fully get the problem and I'd like to ask for some help!

It does its thing beautifully, but at the end it says the return value is none. Could that be the issue? If so, how can I fix it? Thank you!!

import math

def balls(radius):

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

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

    print(grid)

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

@golden scaffold

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.

golden scaffold
#

Also, here's my output. It puts the x's in some places, but it's not looking as I expected and I'm confused

Choose your size: 2
[[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '], [' ', 'x', 'x', 'x', ' ', ' ', ' ', ' '], [' ', 'x', 'x', 'x', ' ', ' ', ' ', ' '], [' ', 'x', 'x', 'x', ' ', ' ', ' ', ' ']]

Process finished with exit code 0
meager prism
#

What are you expecting it to print in that case?

#

And what's looping forever? This seems to end fine.

long prairieBOT
#
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.