Python Coding for Mathematical Problems
Python Coding for Mathematical Problems
Verzosa
CS15L (6542)
import math
# Coefficients
a = float(input("Enter coefficient a: "))
b = float(input("Enter coefficient b: "))
c = float(input("Enter coefficient c: "))
# Discriminant
discriminant = b**2 - 4*a*c
if discriminant > 0:
root1 = (-b + math.sqrt(discriminant)) / (2 * a)
root2 = (-b - math.sqrt(discriminant)) / (2 * a)
print(f"Roots are real and different: {root1:.4f}, {root2:.4f}")
elif discriminant == 0:
root = -b / (2 * a)
print(f"Roots are real and same: {root:.4f}")
else:
real_part = -b / (2 * a)
imaginary_part = math.sqrt(abs(discriminant)) / (2 * a)
print(f"Complex Roots: {real_part:.4f} ± {imaginary_part:.4f}i")
print("-" * 50)
# 3. Calculate Sine, Cosine, and Tangent (SOH-CAH-TOA)
print("3. Calculate SOH-CAH-TOA")
print("-" * 50)
Output