python_Lec-4
python_Lec-4
Iqbal Ahmed
Department of Computer Science and Engineering
University of Chittagong
Python: Dates and Times
A date in Python is not a data type of its own, but we can import
a module named datetime to work with dates as date objects.
import datetime
x = datetime.datetime.now()
print(x)
x = pow(4, 3)
The pow(x, y) function returns the
value of x to the power of y : xy
print(x)
Python: Math Module
import math
The math.sqrt() method for example,
x = math.sqrt(64)
returns the square root of a number
print(x)
Python: Math Module
import math
The math.ceil() method rounds a
number upwards to its nearest x = math.ceil(1.4)
integer, and the math.floor() method y = math.floor(1.4)
rounds a number downwards to its
nearest integer print(x)
print(y)
import math
The math.pi constant, returns the
value of PI x = math.pi
print(x)
Some Mathematical Problems!
Some Mathematical Problems!
Some Mathematical Problems!
Problem 3: Perfect Square Checker
Some Mathematical Problems!
Problem 4: Distance Between Two Points (3D)
1 Solutions!!
import math
A = P * math.pow(1 + r / n, n * t)
dot_product = x1 * x2 + y1 * y2
magnitude_1 = math.sqrt(x1**2 + y1**2)
magnitude_2 = math.sqrt(x2**2 + y2**2)
theta_rad = math.acos(cos_theta)
theta_deg = math.degrees(theta_rad)