- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How To Do Math With Lists in python ?

We not only use lists to store a collection of values, but we also use it to perform some mathematical calculations or operations to do.

**Example 1**

import math data = 21.6 print('The floor of 21.6 is:', math.floor(data))

**Output**

The floor of 21.6 is: 21

**How To Calculate the Weighted Average of a List**

**Example 2**

cost = [0.424, 0.4221, 0.4185, 0.4132, 0.413] cases = [10, 20, 30, 40, 50] cost = [23, 10, 5, 32, 41] weight= [10, 20, 30, 40, 50] for i in range(len(cost)): cost[c] = (cost[i] * weight[i] / sum(weight)) cost = sum(cost) print(cost)

**Output**

72.84444444444445

**Example 3**

import math degree = 180 radian = math.radians(degree) print('The given angle is :', radian ) print('sin(x) is :', math.sin(radian )) print('cos(x) is :', math.cos(radian )) print('tan(x) is :', math.tan(radian ))

**Output**

The given angle is : 3.141592653589793 sin(x) is : 1.2246467991473532e-16 cos(x) is : -1.0 tan(x) is : -1.2246467991473532e-16

**Following are the few Python Math Functions**

- ceil(x):Returns the smallest integer value greater than or equal to x.
- copysign(x, y): Returns x with a sign of y
- fabs(x): Returns the absolute value of x
- factorial(x): Returns the factorial of x
- floor(x): Returns the largest integer less than or equal to x
- fmod(x, y): Returns a remainder when x is divided by y
- frexp(x): Returns a mantissa and exponent of x as the pair (m, e)
- fsum(iterable): Returns the accurate floating point sum of values in the iterable
- isfinite(x): Returns True if x is neither an infinity nor a NaN (Not a Number)
- isinf(x): Returns True if x is the positive or negative infinity
- isnan(x): Returns True if x is the NaN
- ldexp(x, i) : Returns x * (2**i)
- modf(x): Returns a fractional and integer parts of x
- trunc(x): Returns a truncated integer value of x
- exp(x) : Returns e**x
- expm1(x): Returns e**x – 1
- log(x[, base]): Returns the logarithm of x to the base (defaults to e)
- log1p(x) : Returns the natural logarithm of 1+x
- log2(x) : Returns the base-2 logarithm of x

- Related Articles
- How to do Python math at command line?
- How can we do date and time math in Python?
- How do we define lists in Python?
- How do we compare two lists in Python?
- Can we do math operation on Python Strings?
- How do I convert between tuples and lists in Python?
- How do we compare the elements of two lists in Python?
- How to plot 2D math vectors with Matplotlib?
- How to compare two lists in Python?
- How to perform square root without using math module in Python?
- How to force JavaScript to do math instead of putting two strings together?
- How do make a flat list out of list of lists in Python?
- How do you add two lists in Java?
- How to index and slice lists in Python?
- How to join list of lists in python?

Advertisements