Python for Machine Learning Series
This tutorial marks the beginning of a series focused on introducing programming concepts
through practical, code-driven lessons using the Python language. Emphasizing a hands-on
approach, learners are encouraged to actively engage with the material by executing code and
experimenting with examples for an effective learning experience.
Chapter - 1 Introduction to Python
The chapter covers:
• Introduction to Jupyter Notebook
• Arithmetic operations with Python
• Addressing multi-step challenges using variables
• Conditions using Python
• Merging conditions through logical operators
# Introduction to Jupyter Notebook
• In Jupyter, code cells provide an interactive Python coding environment, allowing you to
write, execute, and experiment with your Python scripts.
print("Hello World")
• Markdown cells are used for text and documentation, offering a convenient way to
include explanations, notes, and formatted content.
1. Headings - Fonts controlled using #
AIML
AIML
AIML
AIML
1. Bullet Lists
• AIML
• AIML
• AIML
1. Numbered list
2. AIML
3. AIML
4. AIML
Basics of Jupyter
• Creating a new file
• Opening an existing file
• Inserting a new cell
• Deleting a cell
• Running the cell - Shift + Enter
• Kernel - IPython includes a kernel for Python code
a = 10
b = 20
a,b
(10, 20)
Operations
2 +3
22 -56
3 * 7
21 / 7
10 ** 3
• Word Problems
1. The restaurant has 175 normal chairs and 20 chairs for babies. How many chairs does the
restaurant have in total?
175 + 20
1. A movie theatre has 25 rows of seats with 20 seats in each row. How many seats are
there in total?
25 * 20
500
1. There is a group of 10 people who are ordering pizza. If each person gets 2 slices and
each pizza has 4 slices, how many pizzas should they order?
List out the information given in the problem.
• Number of persons = 10
• Per person Slices = 2
• Per Pizza slices = 4
• Total Slices needed = 10 * 2*
• Total Pizzas needed = Total Slices needed / per Pizza slices
(10 * 2)/4
5.0
So total number of pizzas required are 5.
Variables: While working with a programming language such as Python, informations is stored
in variables. You can think of variables as containers for storing data. The data stored within a
variable is called it's value.
Number_of_persons = 10
Per_person_Slices = 2
Per_Pizza_slices = 4
Total_Slices_needed = 10 * 2
Total_Pizzas_needed = Total_Slices_needed / Per_Pizza_slices
Total_Pizzas_needed
5.0
Print Function
print("The total Pizzas needed are : ",Total_Pizzas_needed)
The total Pizzas needed are : 5.0
print(f"The total Pizzas needed are : {Total_Pizzas_needed}")
The total Pizzas needed are : 5.0
Conditions
Python supports the usual logical conditions from mathematics:
• Equals: a == b
• Not Equals: a != b
• Less than: a < b
• Less than or equal to: a <= b
• Greater than: a > b
• Greater than or equal to: a >= b
The result of a comparision operation is either True or False
# a = 5
# b = 7
# c = 5
a = int(input("Enter Number : "))
b = int(input("Enter Number : "))
c = int(input("Enter Number : "))
# Equals: a == b
print(f"{a} equals {b}: {a == b}") # Output: False
5 equals 7: False
# Not Equals: a != b
print(f"{a} not equals {b}: {a != b}") # Output: True
5 not equals 7: True
# Less than: a < b
print(f"{a} is less than {b}: {a < b}") # Output: True
5 is less than 7: True
# Less than or equal to: a <= b
print(f"{a} is less than or equal to {b}: {a <= b}") # Output: True
5 is less than or equal to 7: True
# Greater than: a > b
print(f"{a} is greater than {b}: {a > b}") # Output: False
5 is greater than 7: False
Logical Operators
• and -- Logical AND: -- True if both the operands are true x and y
• or -- Logical OR: -- True if either of the operands is true x or y
• not -- Logical NOT: -- True if operand is false not x
Combining conditions with logical operators
a b a and b
True True True
True False False
False True False
False False False
# Example 1: AND Operator
x = 5
y = 10
# Both conditions must be true for the result to be True
x > 0 and y >= 0
True
# Example 2: OR Operator
a = -3
b = 7
# At least one condition must be true for the result to be True
a < 0 or b < 0
True
# Example 3: NOT Operator
flag = True
# Negates the condition
not flag
False
Further Reading and References
• Following are some resources to learn about more arithmetic, conditional and
logical operations in Python:
• Python Tutorial at W3Schools: [Link]