can someone please post the correct method of the five click house or the newton's method from zelles book, reward promised,it is xmas?? thanks a mill need this for xmas tests!

Arrrrggghhh!! Where am I going wrong??

from graphics import *
distance = math.sqrt(square(p2.getX() - p1.getX()) + (square(p2.getY() - p2.getY()
def main():

win = GraphWin("house.py", 500, 500)
win.setCoords(0,0, 4,4)

p1=win.getMouse()
p2=win.getMouse()
p3=win.getMouse()
p4=win.getMouse()
p5=win.getMouse()

house = Rectangle(p1, p2)
house.setFill("Red")
house.draw(win)
win.getMouse()


#width one fifth of the area of house
door = Rectangle(p3)
doorwidth = door.setWidth(distance / 5.0)
door.setFill("Brown")
door.draw(win)
#window one forth of the door
window = Rectangle(p4)
window.setWidth(doorwidth/ 4.0)
window.setFill("White")
window.draw(win)

roof = Line(p5, p2)
roof.setFill("Black")
roof.draw(win)
clone = getP5(), getP2()
clone.draw(win) #have to flip this one


win.getMouse()
win.close()
main()

The problem is you aren't thinking it through: you are trying to use things before they exist.

To best help, you need to work on how to convert abstract stuff like "draw a door of a specific width" to the code that actually draws a door.

Do like I suggested in first thread woooee linked, and think about exactly what information
1. that you have
2. that you must calculate
in order to draw each part of the house.

Also, always get only the minimum amount of information you need from the user before drawing each part of the house. Again, read the link woooee listed.

You'll have to think about this a bit more, alas. Good luck.

Something wrong with the door, says attribute not cloned or something, any ideas why??

from graphics import *


def main():

win = GraphWin("house.py", 500, 500)
win.setCoords(0,0, 4,4)

p1=win.getMouse()
p2=win.getMouse()


house = Rectangle(p1, p2)
house.setFill("Red")
house.draw(win)
win.getMouse()
p1.getX()
p2.getX()
distance=(p2.getX()-p1.getX())

#door
p3=win.getMouse()
p8=(p3.getX() + (distance / 5.0),p3.getY())
p7=(p8,p1.getY())
door=Rectangle(p3,p7)
door.draw(win)

win.getMouse()
win.close()
main()

You're doing well; you've just made a simple mistake.

p8 is the upper-left corner of the door
p7 should be the lower-right corner of the door

the mistake is when you say p7=(p8, p8 is a point, not a number... :$

You'll need to add something to p8's x coordinate.

p3=win.getMouse()
p8=(p3.getX() + (distance / 5.0),p3.getY())
p7=(p8.getX(),p1.getY())
door=Rectangle(p3,p7)
door.draw(win)

then i get this :"p7=(p8.getX(),p1.getY())
AttributeError: 'tuple' object has no attribute 'getX'

Ah, yes, my mistake. You are using graphics.py. The type of thing matters. A point is an object, not a tuple.

So, you need to create a point using the appropriate constructor: p8 = [B]Point([/B] p3.getX() + (distance / 5.0), p3.getY() [B])[/B] etc.

Sorry I missed that.

thanks it worked, do you know how to create a square by clicking in the middle to produce it??

Yes. And so do you.

Remember, get out the crayons and construction paper and draw what you are trying to do at each step.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.