Math_Python
Math_Python
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
1. Go to => https://www.python.org/downloads
4. Install Now
1. Go to =>https://www.anaconda.com/distribution
2. Download
3. Windows
7. install
• The first two print statements are indented by 4 spaces, so they belong to
the if block.
+, -, *, /, % Arithmetic
a = 13 OUTPUT
b = 33
a = True OUTPUT
b = False
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
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
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
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
• Questions?