BPP (313011) Practical No.10: Create python program to demonstrate use of math built-in function
Python includes multiple math-related and string-related functions. The math built-in module is used to perform various mathematical calculations, such as numeric, trigonometric, logarithmic, and exponential calculations. The Python string module provides several constants that are useful for checking to see if a character, slice, or string contains letters, digits, symbols, etc. To use these modules, we need to import the module into our code.
Practical related Questions
1. Write the output of the following program.
import math
x = math.ceil(1.4)
y = math.floor(1.4)
print(x)
print(y)
Answer:
2
1
2. Write the output of the following program.
for i in range (3,12,2):
print("a".upper())
Answer:
A
A
A
A
A
3. The function pow(x,y,z) is evaluated as:
a) (x**y)**z
b) (x**y) / z
c) (x**y) % z
Answer:
c)
(x**y) % z
Exercise
1. Write a Python script to calculate factorial of a number using math built-in function.
Answer:
2. Bill is 30 m away from a church. The angle of elevation when he looks at the top of the church’s spire is 45°. If Bill’s eye level is 1.5 m above the ground, how tall is the church spire. (Use math built-in function)
Answer:
3. Write a Python script that accepts a string in lowercase letters and convert into upper case letters using string module.
Answer:
4. Write a Python script that uses find() function to search for the “language” string from the original string "Python is a powerful language" and returns its index in the Python string.
Answer: