#๐Ÿ”’ python homework

49 messages ยท Page 1 of 1 (latest)

unkempt prawn
#

this is the assignment lol

chilly coyoteBOT
#

@unkempt prawn

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.

river widget
#

have you written any code?

unkempt prawn
#

import graphics
import random

win = graphics.GraphWin('Circles', 600 ,600)

top_text=graphics.Text(graphics.Point(300,25), "Click 10 times to draw 10 circles")
top_text.draw(win)
top_text.setSize(15)

count = 1

while count <= 10:

red = random.randint(0,225)
green = random.randint(0,225)
blue = random.randint(0,225)
color = graphics.color_rgb(red, green, blue)

win.getMouse()
p1 = graphics.Point(215,150)
p1 = graphics.Circle(p1, 50)
p1.draw(win)
p1.setFill(color)

win.getMouse()
p2 = graphics.Point(385,150)
p2 = graphics.Circle(p2, 50)
p2.draw(win)
p2.setFill(color)

win.getMouse()
p3 = graphics.Point(300,300)
p3 = graphics.Circle(p3, 50)
p3.draw(win)
p3.setFill(color)

win.getMouse()
p4 = graphics.Point(100,365)
p4 = graphics.Circle(p4,50)
p4.draw(win)
p4.setFill(color)

win.getMouse()
p5 = graphics.Point(150,400)
p5 = graphics.Circle(p5,50)
p5.draw(win)
p5.setFill(color)

win.getMouse()
p6 = graphics.Point(225,440)
p6 = graphics.Circle(p6,50)p6.draw(win)
p6.setFill(color)

win.getMouse()
p7 = graphics.Point(300,450)
p7 = graphics.Circle(p7,50)
p7.draw(win)
p7.setFill(color)

win.getMouse()
p8 = graphics.Point(375,440)
p8 = graphics.Circle(p8,50)
p8.draw(win)
p8.setFill(color)

win.getMouse()
p9 = graphics.Point(450,400)
p9 = graphics.Circle(p9,50)
p9.draw(win)
p9.setFill(color)

win.getMouse()
p10 = graphics.Point(500,365) p10 = graphics.Circle(p10,50)
p10.draw(win)
p10.setFill(color)

bottom_text=graphics.Text(graphics.Point(300,575), "Nice Design!")
bottom_text.draw(win)
bottom_text.setSize(15)
thats the whole line of code i wrote, its drawing the smile but each circle isnt changing colors as i click

#

i was absent when they taught how to do loops with while, so im lost

river widget
#

so while loops are fairly simple

#

in psuedo code its basically
while a condition is true: do this

#

in python it could look like

while x < 5:
    x += 1
    print(x)
``` in this example it will print x while it is less than 5
#

however it adds each iteration so it will only print up till 4

unkempt prawn
#

got it, so how can i combine the mouse clicks with that?

#

like make each circle a different color?

river widget
#

well im not familiar with the graphics library but you would want to call a set color function after each click

#

it looks like p10.setFill(color) may be trying to do that?

#

do you have a picture of your current output?

hallow trench
#

using the random module is prolly what ur loooking for

river widget
#

yeah ok i see now

#

so if you need to get a random color

#

you use random.choice()

unkempt prawn
#

each time i run the code it does in a different color

#

but i need each circle to be a different color

river widget
#

yes because random.choice should be called on each click, right now its only called one time

green walrus
#

This is an easy code

river widget
#

so you need to add something like p10.setFill(random.choice(color))

green walrus
#

create a list called colors

#

import random module

#

then random.choice the list

river widget
#

that is what we are working on

green walrus
#

give me a second , I will make it

topaz aspen
river widget
unkempt prawn
#

teacher wants us to do this tho red = random.randint(0,225)
green = random.randint(0,225)
blue = random.randint(0,225)
color = graphics.color_rgb(red, green, blue)

green walrus
#

i know , i will help with some aspects

river widget
#

so in pseudocode something like p1 setColor to randomColor , right now you are doing p1 setColor to Color (not random)

unkempt prawn
#

i think she wants me to loop the random colors so its a different color each time, no?

river widget
#

!e

import random
colors = ["red", "blue", "green"]
print(f"Random color from my list: {random.choice(colors)}")
print(f"Random color from my list: {random.choice(colors)}")
print(f"Random color from my list: {random.choice(colors)}")
chilly coyoteBOT
#

@river widget :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | Random color from my list: green
002 | Random color from my list: red
003 | Random color from my list: green
river widget
#

see how it can take a random element from a list?

unkempt prawn
#

yeah

#

but like that's from a list of red green and blue isnt it?

hallow trench
#

yeah you wont be using that

#

but see ur teachers code snippet

red = random.randint(0, 255)
#

you can just do this 3 times, each one for a different color value

#
red = random.randint(0, 255)
green = random.randint(0, 255)
blue = random.randint(0, 255)```
#

now u have ur rgb values randomly selected for later use

#

which in ur teachers code snippet is gonna be

color = graphics.color_rgb(red, green, blue)
chilly coyoteBOT
#
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.