import math
import latexify
@latexify.function
def quadratic_roots(a, b, c):
discriminant = b ** 2 - 4 * a * c
root1 = (-b + math.sqrt(discriminant)) / (2 * a)
root2 = (-b - math.sqrt(discriminant)) / (2 * a)
return root1, root2
quadratic_roots
#clcoding.com
import math
import latexify
@latexify.function
def pythagorean_theorem(a, b):
return math.sqrt(a ** 2 + b ** 2)
pythagorean_theorem
#clcoding.com
import math
import latexify
@latexify.function
def compound_interest(P, r, n, t):
return P * (1 + r/n) ** (n*t)
compound_interest
#clcoding.com
import math
import latexify
@latexify.function
def distance(x1, y1, x2, y2):
return math.sqrt((x2-x1)**2 + (y2-y1)**2)
distance
import math
import latexify
@latexify.function
def factorial(n):
if n == 0:
return 1
elif n == 1:
return 1
else:
return n * factorial(n-1)
factorial
0 Comments:
Post a Comment