Showing posts with label Subtraction. Show all posts
Showing posts with label Subtraction. Show all posts

Wednesday, 8 January 2014

Using Python to Perform Mathematical Computations

Python programs can perform all sorts of mathematical computations and display the result. To display the addition, subtraction, multiplication, and division of two numbers, xand y, use the following code:
print(x + y)
print(x – y)
print(x * y)
print(x / y)

1 # Compute expression
>>> print((150-3.5) + (542-6))
682.5

>>> print((150-3.5) - (542-6))
-389.5

>>> print((150-3.5) * (542-6))
78524.0

>>> print((150-3.5) / (542-6))
0.2733208955223881
>>>