Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
8 views

Python Coding for Mathematical Problems

This document provides Python code for solving mathematical problems, including converting degrees to radians, calculating the roots of a quadratic equation, and computing sine, cosine, and tangent values. It demonstrates the use of the math library for mathematical operations and includes user input for coefficients in the quadratic equation. The output displays results for each calculation with appropriate formatting.

Uploaded by

juliaverzosa076
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Python Coding for Mathematical Problems

This document provides Python code for solving mathematical problems, including converting degrees to radians, calculating the roots of a quadratic equation, and computing sine, cosine, and tangent values. It demonstrates the use of the math library for mathematical operations and includes user input for coefficients in the quadratic equation. The output displays results for each calculation with appropriate formatting.

Uploaded by

juliaverzosa076
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Julia V.

Verzosa
CS15L (6542)

Let's Analyze: Python Coding for Mathematical Problems

# Let’s Analyze - Math Functions

import math

# 1. Convert degrees to radians


print("1. Convert degrees to radians")
degree = float(input("Enter angle in degrees: "))
radian = math.radians(degree)
print(f"{degree} degrees in radians is: {radian:.4f}")
print("-" * 50)

# 2. Calculate the quadratic equation


print("2. Calculate the quadratic equation (ax^2 + bx + c = 0)")

# 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")

# Assume the variables:


adj = 10
opp = 5
hyp = 20

# Calculate trigonometric functions


sine = opp / hyp
cosine = adj / hyp
tangent = opp / adj

print(f"Sine (SOH) = {sine:.4f}")


print(f"Cosine (CAH) = {cosine:.4f}")
print(f"Tangent (TOA) = {tangent:.4f}")

print("-" * 50)

Output

You might also like