0% found this document useful (0 votes)
7 views4 pages

Python Topics

The document provides Python code examples for various mathematical concepts including simple and compound interest, Pythagorean theorem, Fibonacci series, mean and median calculations, tuple creation, string manipulation, factorial computation, and algebraic expressions. Each section includes a brief explanation of the formulas and functions used. The code demonstrates practical applications of these mathematical principles in programming.

Uploaded by

mohitjoshi2005mj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Python Topics

The document provides Python code examples for various mathematical concepts including simple and compound interest, Pythagorean theorem, Fibonacci series, mean and median calculations, tuple creation, string manipulation, factorial computation, and algebraic expressions. Each section includes a brief explanation of the formulas and functions used. The code demonstrates practical applications of these mathematical principles in programming.

Uploaded by

mohitjoshi2005mj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Simple & Compound Interest

# Simple Interest

p = 1000 # Principal

r=5 # Rate of Interest

t=2 # Time in years

si = (p * r * t) / 100

print("Simple Interest:", si)

# Compound Interest

ci = p * ((1 + r/100)**t - 1)

print("Compound Interest:", ci)

Explanation:

 Simple Interest = (Principal * Rate * Time) / 100.

 Compound Interest = Principal * ((1 + Rate/100)^Time - 1).

2. Pythagoras Theorem

import math

a=3

b=4

c = [Link](a*a + b*b)

print("Hypotenuse:", c)

Explanation:

 Right-angled triangle: c² = a² + b².

 [Link]() finds the square root.

3. Fibonacci Series
n = 10 # Number of terms

f1, f2 = 0, 1

print(f1, f2, end=' ')

for i in range(2, n):

f3 = f1 + f2

print(f3, end=' ')

f1, f2 = f2, f3

Explanation:

 Series starts with 0 and 1.

 Each number = sum of previous two numbers.

4. Mean & Median

import statistics

data = [10, 20, 30, 40, 50]

mean_value = [Link](data)

median_value = [Link](data)

print("Mean:", mean_value)

print("Median:", median_value)

Explanation:

 Mean = Average of numbers.

 Median = Middle value after sorting.

5. Tuple Function Example

# Creating a tuple

t = (1, 2, 3, 4, 5)

# Using tuple() function

t2 = tuple([6, 7, 8])
print("Tuple 1:", t)

print("Tuple 2:", t2)

Explanation:

 Tuple = Immutable sequence.

 tuple() converts other sequences to tuple.

6. String Uppercase Example

s = "hello world"

upper_s = [Link]()

print("Uppercase:", upper_s)

Explanation:

 .upper() converts string to uppercase.

7. Factorial

import math

num = 5

fact = [Link](num)

print("Factorial of", num, "is", fact)

Explanation:

 Factorial n! = n*(n-1)*...*1.

 [Link]() calculates it easily.

8. Algebra

x=1

y=2

z_input = 3

term1 = (x*x * y) / 3
term2 = (x*x*x * z_input*z_input) / (9 * y)

term3 = (y*y * z_input**5) / (x*x)

z = term1 + term2 + term3

print("Result =", z)

Explanation:

 Computes a custom mathematical expression using variables x, y, z_input.

 Combines three terms with different powers and divisions to get final result.

You might also like