Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pythagoras theorem formula in python

import math


print("
")
print("_____________________Pythagorean Theorem with Python__________________________________")
print("___________________________created by THARCHEN________________________________________")
print("
") 
print("Please note the following indications
")
print("a is the base of the triangle
")
print("b is the height of the triangle
")
print("c is the hypotenus of the triangle
")

side = input("Give the side you want to solve for (a, b, or c): ")

if side == "a":
    print("
")
    print("Let us find the base of the triangle
")
    b = float(input("Height: "))
    c = float(input("Hypotenuse: "))
    a = math.sqrt(c ** 2 - b ** 2)
    print("Base of the triangle is", "%.2f" %a)
    print("
")

elif side == "b":
    print("Let us find the height of the triangle
")
    a = float(input("Base: "))
    c = float(input("Hypotenuse: "))
    b = math.sqrt(c ** 2 - a ** 2)
    print("Height of the triangle is","%.2f" %b)

elif side == "c":
    print("Let us find the hypotenuse of the traingle
")
    a = float(input("Base: "))
    b = float(input("Height: "))
    c = math.sqrt(a ** 2 + b ** 2)
    print("Hypotenuse of the triangle is","%.2f" %c)
else:
    print("The value of hypotenuse is always greater than height and base")
   

def triangle():
    print("               .")
    print("              /|")
    print("             / |")
    print("            /  |")
    print("           /   |")
    print("          /    |")
    print("         /     |")
    print("        /      |")


def  traingle_1():
    print("     ","%.2f" %c, " ","%.2f" %b)

def triangle_2():
    print("      /        |")
    print("     /         |")
    print("    /          |")
    print("   /           |")
    print("  /            |")
    print(" /             |")
    print("/___","%.2f"%a,"____|
")


triangle()
traingle_1()
triangle_2()
 
PREVIOUS NEXT
Tagged: #pythagoras #theorem #formula #python
ADD COMMENT
Topic
Name
7+1 =