#π Loop error?
111 messages Β· Page 1 of 1 (latest)
@calm tundra
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.
def rat(x,y):
rect1 = Rectangle(60,30)
rect1.set_position(x,y)
rect1.set_color(Color.gray)
add(rect1)
rect2 = Rectangle(50,30)
rect2.set_position(x + 35,y - 20)
rect2.set_color(Color.gray)
add(rect2)
rect3 = Rectangle(20,20)
rect3.set_position(x + 20,y - 30)
rect3.set_color(Color.gray)
add(rect3)
rect4 = Rectangle(10,10)
rect4.set_position(x + 60,y - 15)
rect4.set_color(Color.black)
add(rect4)
rect5 = Rectangle(12,12)
rect5.set_position(x + 27,y - 23)
rect5.set_color(Color.red)
add(rect5)
rect6 = Rectangle(12,5)
rect6.set_position(x + 81,y -5)
rect6.set_color(Color.black)
add(rect6)
rect7 = Rectangle(52,5)
rect7.set_position(x - 50, y + 20)
rect7.set_color(Color.black)
add(rect7)
rat()
x_position = 120
y_position = 350
for _ in range (5):
rat(x_position, y_position)
x_position +=20
The error message was that rat was not defined
I was expecting this code to make the rat to move across the screen
I figured it out but now I have another problem
The rat
doesnt move
at all
I think it might have to do with the loop
im not sure
!paste send your entire program in this pastebin
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
all 188 lines
rat is defind within draw_scene1, so it doesn't exist outside of it
but then you try to call it outside of it
hmmm
I get its cause it doesnt exist within the move across function but I honestly dont know what you mean
Im kinda wondering how to fix that
def a():
b = 2
print(b) # error, b does not exist here```
yea
i understand that part
wait
let me try doing something
I will come back
yeah
nvm
I couldnt fix it
I thought putting the loop within the function would solve it but no
You can define the rat function outside of the loop
u can?
could u give me an example
without using my work
please
and thank u
def a():
print(1)
def b():
a()
a()```
OHHH
ok
honestly
I have absolutely no clue what I'm doing wrong

it didnt worl
work***
What is the code like after changing it?
hold on
want a screen shot or should i copy paste
def rat(x,y):
rect1 = Rectangle(60,30)
rect1.set_position(x,y)
rect1.set_color(Color.gray)
add(rect1)
rect2 = Rectangle(50,30)
rect2.set_position(x + 35,y - 20)
rect2.set_color(Color.gray)
add(rect2)
rect3 = Rectangle(20,20)
rect3.set_position(x + 20,y - 30)
rect3.set_color(Color.gray)
add(rect3)
rect4 = Rectangle(10,10)
rect4.set_position(x + 60,y - 15)
rect4.set_color(Color.black)
add(rect4)
rect5 = Rectangle(12,12)
rect5.set_position(x + 27,y - 23)
rect5.set_color(Color.red)
add(rect5)
rect6 = Rectangle(12,5)
rect6.set_position(x + 81,y -5)
rect6.set_color(Color.black)
add(rect6)
rect7 = Rectangle(52,5)
rect7.set_position(x - 50, y + 20)
rect7.set_color(Color.black)
add(rect7)
def move():
x_position = 120
y_position = 350
for x in range (5):
rat(x_position, y_position)
x_position += 20
rat()
Hey @calm tundra!
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
does this still give the same error? It doesn't seem like it should
it runs
just not how I want it to
wops
woops
I shouldve mentioned that
sory
sorry
so
Basically
What do you want it to do and what does it do?
I want it to move to the right
the mouse
or rat
I created a loop so that
It would just add on 20 units
and move it to the right
but
when I press run
it just disappears
by disappear I mean the rat disappears not the whole code
I'll try running it in a second
can you send over the entire file?
is there anything you've imported or defined in a different file? Rectangle is never defined in this file for example
right ok.. looks like ima have to find whatever you're using then π
sorry
I DID IT
I DID IT
DUDE
but now I have another problem ;-;
I have quadruple amount of rats..
ah nice
Was it a case of removing rat() here?
that's what I thought the problem might be - rat() was defined outside that scope, so it didn't think it was defined
yea
Ig you'll need to make a function to delete the old rat
The current one just makes a new rat
rip
:(
This help channel has been closed. 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.