jason1
(Jaosn)
November 10, 2025, 5:35pm
1
I want to be able to get the red ball to stay within the range of the graph window is 600 by 700. Here’s the code I have so far:
‘‘‘
import time
import random
… from graphics import *
… def main():
… dx= int(1)
… dy= int(1)
… win= GraphWin(“shapes”, 600,700)
… center= Point(dx,dy)
… circ= Circle(center, 30)
… circ.setFill(‘red’)
… circ.draw(win)
… for i in range(100):
… dx1=random.randint(1,40)
… dy2=random.randint(1,40)
… circ.move(dx1,dy2)
…
… time.sleep(3)
‘‘‘
MRAB
(Matthew Barnett)
November 10, 2025, 5:44pm
2
In order to preserve formatting, please select any code or traceback that you post and then click the </> button.
If the ball’s position would be outside a range, change the position to be inside the range. All you need to do that are if statements.
2 Likes
pink_dog
(ami)
November 11, 2025, 9:19am
3
your current code moves ball randomly without checking its position, you need to fix it to the ball bouncing inside the window.
c-rob
(Chuck R.)
November 11, 2025, 10:11am
4
Help us help you. Read this link first and learn how to format code so we can help you better. Formatting code Do not use a screen shot of your code, instead paste your code in as preformatted code, as some of us will copy and paste the code to get it to work for you, so you can learn from this. You will get more help this way.