Question

Python Code Question

(10 pts) Write a boolean function, islnRect(t,xc,yc,W,H), which returns True if turtle, t, is inside or on the boundary of a

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import turtle

def isInRect(t,xc,yc,W,H):

    topLeftX = xc-W/2              # calculate the rectangle top left x value
    topLeftY=H/2+yc                # calculate the rectangle top left y value
    bottomRightX=xc+W/2            # calculate the rectangle bottom right x value
    bottomRightY=yc-H/2            # calculate the rectangle bottom right y value

    # return the below expression is True if turtle is inside the rectangle
    return topLeftX<=t.xcor() and t.xcor()<=bottomRightX and bottomRightY<=t.ycor() and t.ycor()<=topLeftY
Add a comment
Know the answer?
Add Answer to:
Python Code Question (10 pts) Write a boolean function, islnRect(t,xc,yc,W,H), which returns True if turtle, t,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python rOverlap (x1, y1, w1, h1, x2, y2, w2, h2) A rectangle is axis-aligned if...

    In Python rOverlap (x1, y1, w1, h1, x2, y2, w2, h2) A rectangle is axis-aligned if its sides are parallel to the coordinate axes. An axis-aligned rectangle will be defined by its bottom left corner (x,y), its (nonnegative) width w, and its (nonnegative) height h. The Cartesian coordinates (x,y) behave in the normal mathematical way: increasing x moves right, increasing y moves up. (In future, we will see situations where different conventions are used.) Write the function rOverlap that tests...

  • Python 2. (10 pts) Write the definition of a function, sqr_10(t), which uses turtle, t, to...

    Python 2. (10 pts) Write the definition of a function, sqr_10(t), which uses turtle, t, to draw a square each side of which is 10 long.

  • Complete code and answer question in comments: Package hw4; import java.util.ArrayList; public c...

    Complete code and answer question in comments: Package hw4; import java.util.ArrayList; public class WordGame { /* * Returns all strings that appear * as a consecutive horizontal or vertical sequence of letters * (left-right, right-left, up-down, or down-up) * in the array board and also appear in dict. * Note that the same word may appear multiple times * on the board, and will then be multiple times in * the returned array. * * dict is assumed to be...

  • 2. (10 pts) A municipality is designing an open storm drain channel in the form of an in verted t...

    2. (10 pts) A municipality is designing an open storm drain channel in the form of an in verted trapezoid. It has a width of L at its base, is symmetric about the vertical, and its sides are at an angle θ to the horizontal (Fig. 2). Assuming the Manning formula, i.e grating for pedestrians where O-v3o./n is fired for this prob- lem (because material and slope are already known), determine Q as a function of Co, L, 0, and...

  • Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which...

    Q1. Write a recursive function in C++ void printNumberedChars(string str, int i=0) { ... } which prints each character of the given string str on a new line, with each line numbered 1, 2, 3, …. For example calling the function with printNumberedChars("hello"); should output the following: 1. h 2. e 3. l 4. l 5. o Q2. Write a recursive function in C++ int sumArray(const int* arr, unsigned int size) { ... } which takes an array of integers,...

  • The both files are included. Where are these which are colorful. Point.h and point.cpp Hor this assignment you are provided the files for a class called point. Download the h and .cpp files and incl...

    The both files are included. Where are these which are colorful. Point.h and point.cpp Hor this assignment you are provided the files for a class called point. Download the h and .cpp files and include them in your project. IheじML diagram below details the class Point くくfriend>> ostream& operator.((ostream&, point&) <ごfriend::. İstream& operator:..イ1stream&-point& - : double - v doublc getX) double getYO double - sctX( double): void - set Y(double) : void - point(double-0.0, double-0.0 operator-(const point& bool perator< const...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT