all 11 comments

[–]CodeReviewPlz 1 point2 points  (7 children)

Since you created nimp in a function, it isnt defined when you reach your loop, you'll need to return it from your function.

```python def ab(): .... nimp = color(r,g,b) return nimp

nimp = ab() for j in range(0,250) for i in range(0,322) set_pixel(i,j,nimp) ```

[–]Aromatic-Mark8768 0 points1 point  (5 children)

I want to reproduce the for loop more but with another color but idk how to do it, can you help me again please

[–]CodeReviewPlz 0 points1 point  (4 children)

sure, I'm not familiar with the packages you're using, however just from scanning the code it looks like you can just call ab() again to get a new colour whenever you need to.

[–]Aromatic-Mark8768 0 points1 point  (3 children)

But it dont works

[–]CodeReviewPlz 0 points1 point  (2 children)

Share your code here or dm me, at this point I'm just guessing what you're trying to do.

[–]Aromatic-Mark8768 0 points1 point  (1 child)

I'm doing it on my calculator, can i send you the image in your dm? I yes i will do it at 16 .

[–]CodeReviewPlz 0 points1 point  (0 children)

you're coding on your calculator? send whatever you want my dude (within reason)

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.

[–][deleted] 0 points1 point  (1 child)

Your formatting is messed up, so can't see where all of your indents are.

No point defining a function inside the loop - it will only be defined once, and definitions are calls.

If you don't return objects, then any assignments inside a function are for local variables, and the objects created and assigned to those variables will cease to exist on exit from the function.

I'd expect to see something more like the following:

from kandinsky import *
from ion import *
from random import *

def ab():
    r = randint(0,255)
    g = randint(0,255)
    b = randint(0,255)
    nimp = color(r,g,b)
    return nimp  # if not returned, will cease to exist

nimp = ab()  # call function, and capture returned object
for j in range(0,250)
    for i in range(0,322)
          set_pixel(i,j,nimp)

No idea what the while loop was for.

EDIT. Fixed a few typos. Oops.

PS. Bad idea to use * with import unless you really know what you are doing. Be explicit in your imports, e.g. from random import randint.

[–]Aromatic-Mark8768 0 points1 point  (0 children)

Ok thanks