0% found this document useful (0 votes)
3 views

Math_Python

The document outlines a seven-day FDP/SDP on 'Principles of Math-Python' organized by the Placement Cell and the Department of Mathematics, featuring Mrs. Archana M A as the resource person. It covers Python programming basics, including installation, syntax, data types, control structures, and various applications in web development, data science, and machine learning. The document emphasizes Python's beginner-friendly nature and its versatility across multiple domains.

Uploaded by

ARIF K F
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Math_Python

The document outlines a seven-day FDP/SDP on 'Principles of Math-Python' organized by the Placement Cell and the Department of Mathematics, featuring Mrs. Archana M A as the resource person. It covers Python programming basics, including installation, syntax, data types, control structures, and various applications in web development, data science, and machine learning. The document emphasizes Python's beginner-friendly nature and its versatility across multiple domains.

Uploaded by

ARIF K F
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Seven Days FDP/SDP

on

“Principles of Math-Python”
Organized by
PLACEMENT CELL
&
DEPARTMENT OF UG, PG STUDIES & RESEARCH IN
MATHEMATICS
IN ASSOCIATION WITH
Aishwarya Academy
Resource Person

Mrs. Archana M A
Introduction to Python
Programming


What is Python?
 High-level, interpreted programming language
 Created by Guido van Rossum in 1991
 Emphasizes readability and simplicity
 Used in web development, data science, AI, etc.
Features of Python

 • Easy to learn and use


 • Interpreted and dynamically typed
 • Extensive standard libraries
 • Cross-platform
 • Supports multiple programming paradigms
 Free to use
Applications of Python
• YouTube: World’s largest video-sharing platform uses Python
for features like video streaming and backend services.
• Instagram: This popular social media app relies on Python’s
simplicity for scaling and handling millions of users.
• Spotify: Python is used for backend services and machine
learning to personalize music recommendations.
• Dropbox: The file hosting service uses Python for both its
desktop client and server-side operations.
• Netflix: Python powers key components of Netflix’s
recommendation engine and content delivery systems (CDN).
• Google: Python is one of the key languages used in Google for
web crawling, testing, and data analysis.
• Uber: Python helps Uber handle dynamic pricing and route
optimization using machine learning.
Installation of Python

 Download from www.python.org OR


 Use www.anaconda.com with 64 bits or 32 bits
depending on your machine where we have
Spyder, Jupyter lab, Jupyter Notebook,
Orange3, Qt Console, Glueviz and RStudio.
 For Python, only Spyder or Jupyter Notebook
is needed.
Installing Python

1. Go to => https://www.python.org/downloads

2. Download the file

3. Double click on downloaded file (check add python 3.7.3 to


path)s

4. Install Now

5. Open python IDLE in search or in all program

6. Start working on IDLE


INSTALLING PACKAGES FOR
PYTHON

1. Go to search and type: cmd command prompt is opened

2. Type: python -m pip install --upgrade pip

3. pip install numpy

4. pip install sympy

5. pip install matplotlib


Installing Anaconda

1. Go to =>https://www.anaconda.com/distribution

2. Download

3. Windows

4. anaconda 2019.03 for Windows installer

5. python 3.7 version 64 bit

6. save the file

7. install

8. work on jupyter lab, jupyter notebook or Spyder


Python Syntax Basics
 Indentation instead of braces: In Python, indentation is used to define
blocks of code. It tells the Python interpreter that a group of statements
belongs to a specific block. All statements with the same level of indentation
are considered part of the same block. Indentation is achieved using
whitespace (spaces or tabs) at the beginning of each line.
 Example:
if 10 > 5:
print("This is true!")
print("I am tab indentation")

print("I have no indentation")

• The first two print statements are indented by 4 spaces, so they belong to
the if block.

• The third print statement is not indented, so it is outside the if block.


Python Syntax Basics
Operators Type

+, -, *, /, % Arithmetic

<, <=, >, >=, ==, != Relational

AND, OR, NOT Logical

&, |, <<, >>, -, ^ Bitwise

=, +=, -=, %= Assignment


Operators
Python Arithmetic operators are used to perform basic
mathematical operations like addition, subtraction,
multiplication and division.
In Python Comparison of Relational
operators compares the values. It either
returns True or False according to the condition.
Python Logical operators perform Logical
AND, Logical OR and Logical NOT operations. It is
used to combine conditional statements.
Python Bitwise operators act on bits and perform bit-
by-bit operations. These are used to operate on
binary numbers.
Python Assignment operators are used to assign
values to the variables. This operator is used to assign
the value of the right side of the expression to the
left side operand.
Example of Arithmetic Operators in Python:
# Variables OUTPUT
a= 15
b=4 Addition: 19
# Addition
Subtraction: 11
print("Addition:", a + b)
Multiplication: 60
# Subtraction
Division: 3.75
print("Subtraction:", a - b) Floor Division: 3
# Multiplication Modulus: 3
print("Multiplication:", a * b) Exponentiation: 50625
# Division
print("Division:", a / b)
# Floor Division
print("Floor Division:", a // b)
# Modulus
print("Modulus:", a % b)
# Exponentiation
print("Exponentiation:", a **
b)
Examples of Relational Operators

a = 13 OUTPUT
b = 33

print(a > b) False


print(a < b) True
print(a == b) False
print(a != b) True
print(a >= b) False
print(a <= b) True
Examples of Logical Operators

a = True OUTPUT
b = False

print(a and b) False


print(a or b) True
print(not a) False
Examples of Assignment Operators

a = 10 OUTPUT
b=a
print(b) 10
b += a
print(b) 20
b -= a
print(b) 10
b *= a
print(b) 100
b <<= a
print(b) 102400
Python Syntax Basics

 • Variables and data types


 • Comments using #
 • Print statement: print("Hello, World!")
Data Types

 • Numbers: int, float


 • Strings: "Hello"
 • Lists: [1, 2, 3]
 • Tuples: (1, 2, 3)
 • Dictionaries: {"name": "Alice"}
 • Boolean: True, False
OUTPUT
a=5
print(type(a)) <class 'int’>

b = 5.0
print(type(b)) <class 'float’>

c = 2 + 4j
print(type(c)) <class 'complex'>
Control Structures
 • Conditionals: if, elif, else
 • Loops: for, while
 • Break / Continue / Pass

Conditional Statements in Python:


If statement is the simplest form of a conditional statement. It
executes a block of code if the given condition is true.
Example:
age = 20
if age >= 18:
print("Eligible to vote.")
Output:
Eligible to Vote.
If else Conditional Statements in Python
 Else allows us to specify a block of code that will execute if the
condition(s) associated with an if or elif statement evaluates
to False. Else block provides a way to handle all other cases
that don't meet the specified conditions.

Example:
age = 10
if age <= 12:
print("Travel for free.")
else:
print("Pay for ticket.")
Output:
Travel for free
Example:
marks = 45
res = "Pass" if marks >= 40 else "Fail"
print(f"Result: {res}")
Output:
Result: Pass
This is an f-string which allows to embed variables directly
into a string.
It will output Result: Pass because res is Pass.

OR
marks = 45 %s is a place holder for string
res = "Pass"
print("Result: %s" % res) %res substitutes the value of
Output: res.
Result: Pass
elif Statement:
elif statement in Python stands for "else if." It allows us to check
multiple conditions , providing a way to execute different blocks
of code based on which condition is true. Using elif statements
makes our code more readable and efficient by eliminating the
need for multiple nested if statements.
Example:

age = 25 Output:
if age <= 12:
print("Child.")
elif age <= 19: Young Adult
print("Teenager.")
elif age <= 35:
print("Young adult.")
else:
print("Adult.")
Nested if..else Conditional Statements
Nested if..else means an if-else statement inside another if
statement. We can use nested if statements to check conditions
within conditions.
Example:

age = 70 Output:
is_member = True

if age >= 60: 30% senior discount


if is_member:
print("30% senior
discount!")
else:
print("20% senior
discount.")
else:
print("Not eligible for a
senior discount.")
Ternary Conditional Statement:
A ternary conditional statement is a compact way to write an if-
else condition in a single line. It’s sometimes called a "conditional
expression.“
Example:
# Assign a value based on a condition
age = 20
s = "Adult" if age >= 18 else "Minor"

print(s)
Output:
Adult
While Loop in Python
In Python, a while loop is used to execute a block of statements
repeatedly until a given condition is satisfied. When the condition
becomes false, the line immediately after the loop in the program is
executed.
Python While Loop Syntax:
while expressions:
Statement(s)
Syntax of While Loop with else statement:
While condition:
Statements # execute these statements
else:
Statements # execute these statements
For Loop Syntax:
For iterator_var in sequence:
Statement(s)
Functions in Python

 • Defined using def


 • Parameters and return values
 • Example:
 def greet(name):
 return "Hello " + name
Modules and Packages

 • Importing modules: import math


 • Built-in vs. third-party modules
 • Installing packages with pip
File Handling

 • Opening files: open("file.txt", "r")


 • Reading and writing
 • Closing files
Python Applications

 • Web development (Django, Flask)


 • Data science (Pandas, NumPy)
 • Machine learning (scikit-learn, TensorFlow)
 • Automation and scripting
Summary

 • Python is beginner-friendly and versatile


 • Core concepts: syntax, data types, control structures,
functions
 • Applications span across many domains
Q&A

 • Questions?

You might also like