Hello everyone, I'm obviously having trouble with a program that wants me to create a house with just five mouse clicks.
My program is simple create a house using only 5 mouse clicks.
This problem is from the book Python Programming by John Zelle
Its on page 162
This is what the book says on the problem:
You are to write a program that allows the user to draw a simple house using five mouse clicks. The first two clicks will be the opposite corners of the rectangle frame of the house. The third click will indicate the center of teh top edge of a rectangular door. The door should have a total width that is 1/5th of the width of the house frame. The sides of the door should extend from the corners of the top down to the bottom of the frame. The fourth click will indicate the center of a square window. The window is half as wide as the door. The last click will indicate the peak of the roof. The edges of the roof will extend from the point at the peak to the corners of the top edge of the house frame.
Thanks for the help in advance.
PS I'm using python 2.2.3 version
So far this is what I have come up with:
from graphics22 import *
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)
roof = Polygon(p1, p3, p4)
roof.setFill("Black")
roof.draw(win)
#door = Rectangle ()
#door.setFill("Brown")
#door.draw(win)
#window = Rectangle()
#window.setFill("White")
#window.draw(win)
win.getMouse()
win.close()
main()
I can create the rectangle for the base of the house and the roof but then I'm already at 4 mouse clicks.