So I have to create and iterative function that random produces shapes of different sizes after the user is prompted to enter the number of circles. I also need to keep track of the total radii after all the circles are drawn. I have set functions for the max of all the variables.
def drawBubbleIter(num):
while num > 0:
red = ...
green = ...
blue = ...
color...
begin_fill()
circle(random.randint(1,MAX_RADIUS()))
end_fill()
up()
rt(random.randint(-MAX_ANGLE(), MAX_ANGLE()))
fd(random.randint(1, MAX_DISTANCE()))
num = num -1
This creates random circles of shapes colors and moves at random distances and angles. How could I attempt to keep track of the radii?
i think you want to store them in a list or something:
radii = []
while num > 0:
r = random.randint(1,MAX_RADIUS())
radii.append(r)
...
How about putting the random radius into a list:
radii = []
while num > 0:
...
r = random.randint(1,MAX_RADIUS())
radii.append(r)
circle(r)
...
print("the sum of all the radii is", sum(radii))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.