Scroll to Top

Virtual Math Learning Center

Virtual Math Learning Center Texas A&M University Virtual Math Learning Center

Using Variables in Python

Author: David Manuel

In this video, it is explained how to define variables and use them in equations in Python. The presenter uses Python to solve for the area of a triangle given the lengths of the three sides.

Transcript 02

Problem: Find area of triangle with side lengths 100, 150, and 200 cm.

Python Code: 
from sympy import *

#Find area of triangle with side lengths 100, 150, and 200 cm
a=100
b=150
c=200
s=(a+b+c)/2
# Area = square root of s(s-a)(s-b)(s-c)
Area=sqrt(s*(s-a)*(s-b)*(s-c))
print('The area of the triangle is', Area, 'square centimeters')

Open Python Notebook File

See more videos from this section