Page 161 - CodePilot V5.0 C8
P. 161
The math module also has some constants. One of the most commonly used constants is pi:
Constant Description
math.pi Returns the value of π (approximately 3.14159)
Program 20 A program to demonstrate the use of various methods in the Math module.
Program20.py
File Edit Format Run Options Window Help
# Importing Math Module
import math
x = 20.5
y = 4
print("Ceil of x:", math.ceil(x))
print("Floor of x:", math.floor(x))
print("Factorial of y:", math.factorial(y))
print("fmod of x/y:", math.fmod(x, y))
print("GCD of int(x) and y:", math.gcd(int(x), y))
print("x to the power y:", math.pow(x, y))
print("Square root of y:", math.sqrt(y))
The output of the preceding code would be as follows:
Output
Ceil of x: 21
Floor of x: 20
Factorial of y: 24
fmod of x/y: 0.5
GCD of int(x) and y: 4
x to the power y: 176610.0625
Square root of y: 2.0
21 st #Critical Thinking
INTERDISCIPLINARY LEARNING Century #Technology Literacy
Skills
Write a Python program to calculate the area and volume of any two 3D shapes (cuboid, cylinder,
cone, sphere). Use pi and pow() from the math module, take required inputs and display only the
integer part using a suitable math function.
mathematics
159
Step Ahead with Python

