Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Python Code:
- import turtle
- import math
- #setup screen
- s = turtle.Screen()
- s.setup(800, 600)
- #turtle
- t = turtle.Turtle()
- #get input
- side1 = int(input("Enter side1: "))
- side2 = int(input("Enter side2: "))
- angle = int(input("Enter angle: "))
- #from law of cosines c^2 = a^2 + b^2 - 2abcosC
- side3 = math.sqrt(side1*side1 + side2*side2 - 2*side1*side2*math.cos(math.radians(angle)))
- angle2 = math.degrees(math.acos((side2*side2 + side3*side3 - side1*side1)/(2*side2*side3)))
- #draw triangle
- t.forward(side1)
- t.left(180-angle)
- t.forward(side2)
- t.left(180-angle2)
- t.forward(side3)
- Input:
- https://d2vlcm61l7u1fs.cloudfront.net/media%2F1f7%2F1f76b54a-7c3e-4539-909a-31f95d6e6bb7%2FphpIv6LdL.png
- Output:
- https://d2vlcm61l7u1fs.cloudfront.net/media%2F9d5%2F9d5e87ac-59c4-4d85-9bef-35e1c4b47d85%2FphpyfBdPG.png
Advertisement
Add Comment
Please, Sign In to add comment