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
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
ADVERTISEMENT