jaredec18

Untitled

Sep 27th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. Python Code:
  2.  
  3. import turtle
  4.  
  5. import math
  6.  
  7. #setup screen
  8.  
  9. s = turtle.Screen()
  10.  
  11. s.setup(800, 600)
  12.  
  13. #turtle
  14.  
  15. t = turtle.Turtle()
  16.  
  17. #get input
  18.  
  19. side1 = int(input("Enter side1: "))
  20.  
  21. side2 = int(input("Enter side2: "))
  22.  
  23. angle = int(input("Enter angle: "))
  24.  
  25. #from law of cosines c^2 = a^2 + b^2 - 2abcosC
  26.  
  27. side3 = math.sqrt(side1*side1 + side2*side2 - 2*side1*side2*math.cos(math.radians(angle)))
  28.  
  29. angle2 = math.degrees(math.acos((side2*side2 + side3*side3 - side1*side1)/(2*side2*side3)))
  30.  
  31. #draw triangle
  32.  
  33. t.forward(side1)
  34.  
  35. t.left(180-angle)
  36.  
  37. t.forward(side2)
  38.  
  39. t.left(180-angle2)
  40.  
  41. t.forward(side3)
  42.  
  43. Input:
  44. https://d2vlcm61l7u1fs.cloudfront.net/media%2F1f7%2F1f76b54a-7c3e-4539-909a-31f95d6e6bb7%2FphpIv6LdL.png
  45. Output:
  46. https://d2vlcm61l7u1fs.cloudfront.net/media%2F9d5%2F9d5e87ac-59c4-4d85-9bef-35e1c4b47d85%2FphpyfBdPG.png
Advertisement
Add Comment
Please, Sign In to add comment