# How to Conquer Your Math Class Using Python

Tyler (291)
Total time: 15 minutes

This guide will teach you how to use your Python programming skills to conquer your math class!

Posted in these interests:
h/python67 guides

## Use the iPython shell instead of a calculator

A calculator can be faster for simple calculations, but there are a lot of benefits to using iPython. If you don't know what iPython is, check it out here. iPython is an interactive python shell with a lot of rich functionality.

Once installed, you can start the iPython shell by opening your Terminal application and typing:

``ipython``

One major benefit of using iPython for your calculations is that you can easily see your history. Many math problems have multiple steps and it's helpful to have your previous calculations visible.

Even more valuable is the ability to save your output as a variable. If you're new to programming this is extremely valuable for problems with multiple steps.

``````rate = 700.0/15000
22000 * rate
-> 1026.6666666666667``````

Using the Python shell will help you learn the language and programming in general.

## Use Python's standard libraries and built in functions

Python, like many other languages, comes with great built-in functionality. For example, Python's math module comes with all sorts of helpful functionality like powers and logarithms, trigonometric functions, hyperbolic functions, and more. The best way to learn this and any other module is to read the docs, but here's a small taste of what is available.

``````import math

math.log(3)
-> 1.0986122886681098

# constants
math.e
-> 2.718281828459045

math.log(math.e)
-> 1.0``````

``````# rounding
round(1.234499, 3)
-> 1.234

# absolute value
abs(-3)
-> 3

# power
pow(3, 2)
-> 9.0

# sum
sum([0, 8, 11, 20, 5])
-> 44``````
``````from fractions import Fraction

Fraction(1, 2) + Fraction(3, 5)
-> Fraction(11, 10)``````

## Use functions to represent common formulas

Oftentimes in your math class you'll have to solve the same kind of problem over and over. You can write your own functions in Python to save time.

To solve the quadratic equation (ax**2 + bx + c = 0), you can write a function that represents the quadratic formula.

``````import math

# the discriminant
d = (b**2) - (4 * a * c)

# find both solutions
s1 = (-b + math.sqrt(d)) / (2 * a)
s2 = (-b - math.sqrt(d)) / (2 * a)

print("Solution is {0}, {1}".format(s1, s2))``````

``````quadratic(1, 5, 6)
# Solution is -2.0, -3.0``````

Good programmers are often considered lazy because they like to automate repetitive tasks. If you find yourself wasting time by writing the same formula over and over, it might be time to write a function. If you get really good at this and use it frequently, you might want to learn how to write your own Python module to organize your functions.

Tyler
Joined in 2015
Software Engineer and creator of howchoo.
Related to this guide:
Get the latest edition of Python in just minutes.
In these interests: codewindowspython
Run Python scripts in command prompt without typing the whole path.
In these interests: windowscodepython
You can run any Python script in a command-line interface.
In these interests: python
Got a Python question? We've probably answered it here.
Not sure what version of Python you’re running? Time to find out!
Specify a parallel filesystem cache for compiled bytecode
AKA the Walrus Operator
Learn how to use formatted string literals in Python
Posted in these interests:
h/python 67 guides
Python is howchoo's favorite programming language. We believe python promotes the most organized and performant codebase possible. We also love Django so, naturally, we love Python.
Discuss this guide:
We're hiring!
Are you a passionate writer? We want to hear from you!

Follow @howchoo and learn cool things:

Like what we do?

Want to support Howchoo? When you buy a tool or material through one of our Amazon links, we earn a small commission as an Amazon Associate.