I\'m having a problem trying to write Python code for drawing an isosceles trian
ID: 3630566 • Letter: I
Question
I'm having a problem trying to write Python code for drawing an isosceles triangle. Using Lines and Points.
I've posting the code I've written so far, can you help?;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
import graphics
def main():
win = graphwin("Python Graphics", 500, 500)
win.getmouse()
win.close()
start = Point(100, 100)
finish = Point(50, 100, 130)
l = Line(start, finish)
l.draw(win)
def point():
p = Point
t.draw(win)
win.getMouse()
win.close()
main ()
Explanation / Answer
Here is some code for you to try. Perhaps you may have to change the first line to import graphics depending on your installation. As always, let me know if you have any question. I'll rush over a fix.
from graphics import *
def drawTriangle(x,y,height,win):
sin60 = 0.8660254
x1 = Point( x , y )
x2 = Point( x + height/sin60 , y )
c = Line( x1 , x2 )
c.draw(win)
x3 = Point( x + height/sin60/2 , y - height )
c = Line( x2 , x3 )
c.draw(win)
c = Line( x3 , x1 )
c.draw(win)
def main():
win = GraphWin("Python Graphics", 500, 500)
drawTriangle( 50 , 100 , 70 , win )
win.getMouse() # pause for click in window
win.close()
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.