[Tutor] Help!!

Shooby Herrmann shooby.herrmann at icloud.com
Mon Sep 26 18:50:57 EDT 2016


Hi,

I am using JES.  I need to write a program and find all pixels in a circle
and in a square. Here is what I have written with the more detailed purpose
of the program.  I know this is not correct, but I'm not sure how to fix it.
Please help.

 

#The purpose of this assignment is to give you practice in function calls
and if statements. Your program will have the user

#to draw a random circle and a random rectangle and to guess which shape has
more pixels. It will time how long the user

#takes to do this and will connect the circle, the rectangle, and the
outline of the picture with colored lines. 

from random import*

def main():

  #Make an empty white 500x500 picture.

  pic= makeEmptyPicture(500, 500, white)

  #Assign variable radius to random value from 10 to 120 (Why this range?).

  radius= randrange(10, 121)

  xCircle= randrange(0, 501)

  yCircle= randrange(0, 501)

  #Draw a circle with this radius anywhere in the picture - show the whole
circle inside the picture.

  circle= addOvalFilled(pic, xCircle, yCircle, radius, radius)

  #Assign the variable numPxCircle to the number of pixels in this circle.

  numPxCircle= getPixels(pic)

  #Assign variables x and y to random values from 5 to 200 (Why this
range?).

  x= randrange(5, 201)

  y= randrange(5, 201)

  #Assign variables width and height to random values.

  # - find the ranges of the values that will show the whole rectangle
inside the picture.

  w= randrange(0, 501)

  h= randrange(0, 501)

  #Draw a green rectangle at the position (x,y) with this width and height
on the picture:

  # - (x, y) is the upper left-hand corner of the rectangle.

  #Assign the variable numPxRectangle to the number of pixels in this
rectangle.

  rectangle= addRectFilled(pic, x, y, w, h, green)

  numPxRectangle= getPixels(pic)

  #Show the picture.

  show(pic)

  #Ask the user, "Which one has more pixels (type 'r' or 'c')?"

  info= requestString("Which one has more pixels? (type r or c).")

  #If the answer is correct, fill the circle with red and pop up an
information box saying "Congratulations!".

  if info== (numPxRectangle >= numPxCircle) :

    showInformation("Congradulations!")

  #If the answer is incorrect, pop up an information box saying "Sorry.
Bye!"

  #(Make sure that the full circle and the full square are shown inside the
picture.)



More information about the Tutor mailing list