SAMANTUS Python for Data Analytics — Complete Training Manual MODULE 04
← Back to Course Index

Numbers


On This Page

Module 4: Numbers


4.1  Integers

An integer (int) is a whole number — positive, negative, or zero — with no decimal point. Python integers have no fixed size limit, unlike many other languages.

► Working with Integers
students = 45
batches = -2       # negative integers are valid
big_number = 123456789012345
print(students, batches, big_number)
print(type(students))
Output
45 -2 123456789012345
<class 'int'>
ℹ Note
Unlike languages like Java or C, Python's int has no maximum size limit — it can grow as large as your computer's memory allows.

4.2  Float

A float represents a number with a decimal point, used for prices, percentages, measurements, and any value requiring precision.

► Working with Floats
course_fee = 15000.50
gst_rate = 0.18
pi_value = 3.14159
print(course_fee, gst_rate, pi_value)
print(type(course_fee))
Output
15000.5 0.18 3.14159
<class 'float'>
✗ Common Mistake
Floating point math can sometimes show tiny rounding errors, e.g. 0.1 + 0.2 gives 0.30000000000000004 instead of exactly 0.3. Use round() when displaying results to users.

4.3  Complex Numbers

Python also supports complex numbers, written as a + bj, where 'j' represents the imaginary part. These are rarely used in business analytics but are common in scientific and engineering computing.

► Complex Number Example
z = 3 + 4j
print(z)
print(z.real)   # real part
print(z.imag)   # imaginary part
print(type(z))
Output
(3+4j)
3.0
4.0
<class 'complex'>

4.4  Type Conversion

You can convert freely between int, float, and complex using built-in functions.

FunctionConverts ToExample
int(x)Integerint(9.8) → 9
float(x)Floatfloat(10) → 10.0
complex(x)Complexcomplex(5) → (5+0j)

4.5  Mathematical Functions

Python has several built-in functions for common numeric operations — no import needed.

FunctionPurposeExample
abs(x)Absolute (positive) valueabs(-15) → 15
round(x, n)Rounds to n decimal placesround(9.876, 2) → 9.88
pow(x, y)x raised to power ypow(2, 5) → 32
max(a,b,...)Largest valuemax(4, 9, 2) → 9
min(a,b,...)Smallest valuemin(4, 9, 2) → 2
sum(list)Total of a list of numberssum([10,20,30]) → 60
► Using Built-in Math Functions
marks = [78, 85, 92, 66, 88]
print("Highest:", max(marks))
print("Lowest:", min(marks))
print("Total:", sum(marks))
print("Average:", round(sum(marks)/len(marks), 2))
Output
Highest: 92
Lowest: 66
Total: 409
Average: 81.8

4.6  The Math Module

For advanced mathematical operations (square roots, logarithms, trigonometry), Python provides the built-in math module, which must be imported first.

► Using the math Module
import math

print(math.sqrt(64))       # square root
print(math.ceil(4.2))      # round UP
print(math.floor(4.8))     # round DOWN
print(math.factorial(5))   # 5! = 120
print(math.pi)             # value of pi
Output
8.0
5
4
120
3.141592653589793
✓ Instructor Tip
Show students the difference between round(), math.ceil(), and math.floor() side by side with the same number — this is one of the most confusing areas for beginners.

4.7  Practical Exercises

Basic (5 Questions)

1. Store your age as an integer and your height (in meters) as a float, then print both.

2. Use abs() to print the absolute value of -45.

3. Round the number 7.6789 to 2 decimal places.

4. Find the maximum and minimum of 5 numbers using max() and min().

5. Import the math module and print the value of pi.

Intermediate (5 Questions)

1. Calculate the average of 6 student marks stored in a list using sum() and len().

2. Use math.sqrt() to find the square root of a number entered by the user.

3. Compare math.ceil() and math.floor() on the number 6.3 and explain the difference.

4. Write a program to calculate compound interest using pow().

5. Create a program that converts a float course fee into an integer and explains what is lost.

Advanced (5 Questions)

1. Build a 'Marks Analyzer': given a list of marks, print the highest, lowest, total, and average.

2. Write a program to calculate the EMI-style monthly payment using basic math functions.

3. Explain why 0.1 + 0.2 does not exactly equal 0.3 in Python, with a code demonstration.

4. Use math.factorial() to calculate the number of ways to arrange 6 students in a row.

5. Create a GST Calculator that takes a price, applies 18% GST, and rounds the final amount to 2 decimals.

4.8  Module Quiz (MCQs)

Q1. Which data type represents whole numbers?

Q2. What does round(9.876, 2) return?

Q3. Which module must be imported to use sqrt()?

Q4. What does math.ceil(4.2) return?

Q5. What is the result of pow(2, 3)?

ℹ Answer Key
1-b, 2-b, 3-c, 4-b, 5-b

4.9  Module Assignment

Assignment: Course Fee & GST Calculator

Expected Output: A script that correctly computes GST-inclusive course fees and displays a clean, rounded final amount — usable as a real billing helper for the institute.

4.10  Interview Questions — Module 4


4.11  Student Notes Page

Use this space to write down key points, doubts, and your own examples from today's session.