SlideShare a Scribd company logo
Basic Math using Python
Dr. Shivakumar B. N.
Assistant Professor
Department of Mathematics
CMR Institute of Technology
Bengaluru
History of Python
▪ It is a general-purpose interpreted, interactive,
object-oriented, and high-level programming
language.
▪ It was created by Guido van Rossum (Dutch
Programmer) during the period 1985- 1990.
▪ Python 3.9.2 is current version
Guido van Rossum
Inventor of Python
Interesting facts about Python Programming
1. Python was a hobby project
2. Why it was called Python [The language’s name isn’t about snakes, but
about the popular British comedy troupe Monty Python]
3. Flavors of Python
Python ships in various flavors:
• CPython- Written in C, most common implementation of Python
• Jython- Written in Java, compiles to bytecode
• IronPython- Implemented in C#, an extensibility layer to frameworks
written in .NET
• Brython- Browser Python, runs in the browser
• RubyPython- Bridge between Python and Ruby interpreters
• PyPy- Implemented in Python
• MicroPython- Runs on a microcontroller
Scope of learning Python in the field of Mathematics:
▪ Data Analytics
▪ Big Data
▪ Data Mining
▪ https://solarianprogrammer.com/2017/02/25/install-numpy-scipy-matplotlib-python-3 ( To install packages)
▪ windows/https://www.w3schools.com/python/default.asp
▪ https://www.tutorialspoint.com/python/python_environment.htm
▪ https://www.udemy.com/course/math-with-python/ (Cover picture)
▪ https://data-flair.training/blogs/python-career-opportunities/ (companies using python picture)
▪ https://geek-university.com/python/add-python-to-the-windows-path/ (To set path)
▪ https://www.programiz.com/python-programming/if-elif-else
Steps to install Python:
Basic Python Learning
Exercise 1: To print a message using Python IDE
Syntax: print ( “ Your Message”)
Example code:
print (“Hello, I like Python coding”)# Displays the message
in next line
# Comments
Variables
13
▪ Variables are nothing but reserved memory locations to store values.
▪ We are declaring a variable means some memory space is being reserved.
▪ In Python there is no need of declaring variables explicitly, if we assign a value it , automatically gets
declared.
Example:
counter = 100 # An integer assignment
miles =1000.0 # A floating point
name =(“John”) # A string
print counter
print miles
print name
Rules to Name Variables
▪ Variable name must always start with a letter or underscore symbol i.e, _
▪ It may consist only letters, numbers or underscore but never special symbols like @, $,%,^,* etc..
▪ Each variable name is case sensitive
Good Practice : file file123 file_name _file
Bad Practice : file.name 12file #filename
Types of Operators
Operator Type Operations Involved
Arithmetic Operator + , - , * , / , % , **
Comparison/ Relational
Operator
== , != , < , > , <= , >=
Assignment Operator = , += , - =, *=, /=, %=, ** =
Logical Operator and, or , not
Identity Operator is , isnot
Operators Precedence Rule
Operator
Symbol
Operator Name
( ) Parenthesis
** Exponentiation (raise to the power)
* / % Multiplication , Division and
Modulus(Remainder)
+ - Addition and Subtraction
<< >> Left to Right
Let a = 10 and b = 20
Python Arithmetic Operators
Python Comparison Operators
Python Assignment Operators
Operators Precedence Example
CONDITIONAL STATEMENTS
One-Way Decisions
Syntax:
if expression:
statement(s)
Program:
a = 33
b = 35
if b > a:
print("b is greater than a")
Indentation
Python relies on indentation (whitespace at
the beginning of a line) to define scope in the
code. Other programming languages often use
curly-brackets for this purpose.
Two-way Decisions
Syntax:
if expression:
statement(s)
Else or elif:
statement(s)
Program:
a = 33
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
Multi-way if
Syntax:
if expression1:
statement(s)
if expression2:
statement(s)
elif expression3:
statement(s)
elif expression4:
statement(s)
else:
statement(s)
else:
statement(s)
Program:
a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
LOOPS AND ITERATION
Repeated Steps
Syntax:
While expression:
Body of while
Program:
count = 0
while (count < 3):
count = count + 1
print("Hello all")
For Loop
Syntax:
for val in sequence:
Body of for
Program:
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
Looking at in:
• The iteration variable "iterates through the sequence (ordered
set)
• The block (body) of code is executed once for each value in the
sequence
• The iteration variable moves through all the values in the sequence
The range() function
The range() function returns a sequence of numbers, starting from 0 by
default, and increments by 1 (by default), and ends at a specied number.
Program 1:
x = range(6)
for n in x:
print(n)
Program 2:
x = range(2,6)
for n in x:
print(n)
Program 3:
x = range(2,20,4)
for n in x:
print(n)
Quick Overview of Plotting in Python
https://matplotlib.org/
Use the command prompt to install the following:
✓ py -m pip install
✓ py -m pip install matplotlib
pip is a package management system used to install and manage software
packages written in Python.
import matplotlib.pyplot as plt
# line 1 points
x1 = [1,2,3]
y1 = [2,4,1]
# plotting the line 1 points
plt.plot(x1, y1, label = "line 1")
# line 2 points
x2 = [1,2,3]
y2 = [4,1,3]
# plotting the line 2 points
plt.plot(x2, y2, label = "line 2")
# naming the x axis
plt.xlabel('x - axis')
# naming the y axis
plt.ylabel('y - axis')
# giving a title to my graph
plt.title('Two lines on same graph!')
# show a legend on the plot
plt.legend()
# function to show the plot
plt.show()
Plotting two or more lines on same plot
import matplotlib.pyplot as plt
# x-coordinates of left sides of bars
left = [1, 2, 3, 4, 5]
# heights of bars
height = [10, 24, 36, 40, 5]
# labels for bars
tick_label = ['one', 'two', 'three', 'four', 'five']
# plotting a bar chart
plt.bar(left, height, tick_label = tick_label,
width = 0.8, color = ['red', 'green'])
# naming the x-axis
plt.xlabel('x - axis')
# naming the y-axis
plt.ylabel('y - axis')
# plot title
plt.title('My bar chart!')
# function to show the plot
plt.show()
Bar Chart
import matplotlib.pyplot as plt
# defining labels
activities = ['eat', 'sleep', 'work', 'play']
# portion covered by each label
slices = [3, 7, 8, 6]
# color for each label
colors = ['r', 'y', 'g', 'b']
# plotting the pie chart
plt.pie(slices, labels = activities, colors=colors,
startangle=90, shadow = True, explode = (0, 0, 0.1, 0),
radius = 1.2, autopct = '%1.1f%%')
# plotting legend
plt.legend()
# showing the plot
plt.show()
Pie-chart
# importing the required modules
import matplotlib.pyplot as plt
import numpy as np
# setting the x - coordinates
x = np.arange(0, 2*(np.pi), 0.1)
# setting the corresponding y - coordinates
y = np.sin(x)
# potting the points
plt.plot(x, y)
# function to show the plot
plt.show()
Plotting curves of given equation: 𝑺𝒊𝒏 𝒙
PYTHON FOR EVERYBODY
(https://www.python.org/)
For More Details:
• http://www.pythonlearn.com/
• https://www.py4e.com/lessons
Thank you
&
Happy Coding

More Related Content

What's hot

Python ppt
Python pptPython ppt
Python ppt
Rohit Verma
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
Python Pandas
Python PandasPython Pandas
Python Pandas
Sunil OS
 
Thermodynamics Part 1 by Shobhit Nirwan.pdf
Thermodynamics Part 1 by Shobhit Nirwan.pdfThermodynamics Part 1 by Shobhit Nirwan.pdf
Thermodynamics Part 1 by Shobhit Nirwan.pdf
Will
 
Chapter 17 - Multivariable Calculus
Chapter 17 - Multivariable CalculusChapter 17 - Multivariable Calculus
Chapter 17 - Multivariable Calculus
Muhammad Bilal Khairuddin
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
Kamal Acharya
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
AkshayAggarwal79
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data Analysis
Andrew Henshaw
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
Kavindu Sachinthe
 
Operation research techniques
Operation research techniquesOperation research techniques
Operation research techniques
Rodixon94
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
Mohd Sajjad
 
Python basic
Python basicPython basic
Python basic
Saifuddin Kaijar
 
Python iteration
Python iterationPython iteration
Python iteration
dietbuddha
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expression
Megha V
 
Plotting data with python and pylab
Plotting data with python and pylabPlotting data with python and pylab
Plotting data with python and pylab
Giovanni Marco Dall'Olio
 

What's hot (15)

Python ppt
Python pptPython ppt
Python ppt
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
Thermodynamics Part 1 by Shobhit Nirwan.pdf
Thermodynamics Part 1 by Shobhit Nirwan.pdfThermodynamics Part 1 by Shobhit Nirwan.pdf
Thermodynamics Part 1 by Shobhit Nirwan.pdf
 
Chapter 17 - Multivariable Calculus
Chapter 17 - Multivariable CalculusChapter 17 - Multivariable Calculus
Chapter 17 - Multivariable Calculus
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data Analysis
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
 
Operation research techniques
Operation research techniquesOperation research techniques
Operation research techniques
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Python basic
Python basicPython basic
Python basic
 
Python iteration
Python iterationPython iteration
Python iteration
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expression
 
Plotting data with python and pylab
Plotting data with python and pylabPlotting data with python and pylab
Plotting data with python and pylab
 

Similar to Python.pdf

Python basics
Python basicsPython basics
Python basics
Hoang Nguyen
 
Python basics
Python basicsPython basics
Python basics
Young Alista
 
Python basics
Python basicsPython basics
Python basics
Fraboni Ec
 
Python basics
Python basicsPython basics
Python basics
Harry Potter
 
Python basics
Python basicsPython basics
Python basics
James Wong
 
Python basics
Python basicsPython basics
Python basics
Tony Nguyen
 
Python basics
Python basicsPython basics
Python basics
Luis Goldster
 
MODULE. .pptx
MODULE.                              .pptxMODULE.                              .pptx
MODULE. .pptx
Alpha337901
 
Python basics
Python basicsPython basics
Python basics
Manisha Gholve
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
BAINIDA
 
Python basics
Python basicsPython basics
Python basics
TIB Academy
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
Utkarsh Sengar
 
Python programming
Python  programmingPython  programming
Python programming
Ashwin Kumar Ramasamy
 
Python language data types
Python language data typesPython language data types
Python language data types
James Wong
 
Python language data types
Python language data typesPython language data types
Python language data types
Harry Potter
 
Python language data types
Python language data typesPython language data types
Python language data types
Hoang Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data types
Young Alista
 
Python language data types
Python language data typesPython language data types
Python language data types
Luis Goldster
 
Python language data types
Python language data typesPython language data types
Python language data types
Tony Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data types
Fraboni Ec
 

Similar to Python.pdf (20)

Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
Python basics
Python basicsPython basics
Python basics
 
MODULE. .pptx
MODULE.                              .pptxMODULE.                              .pptx
MODULE. .pptx
 
Python basics
Python basicsPython basics
Python basics
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
Python basics
Python basicsPython basics
Python basics
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Python programming
Python  programmingPython  programming
Python programming
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Python language data types
Python language data typesPython language data types
Python language data types
 

Recently uploaded

ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 

Recently uploaded (20)

ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 

Python.pdf

  • 1. Basic Math using Python Dr. Shivakumar B. N. Assistant Professor Department of Mathematics CMR Institute of Technology Bengaluru
  • 2.
  • 3. History of Python ▪ It is a general-purpose interpreted, interactive, object-oriented, and high-level programming language. ▪ It was created by Guido van Rossum (Dutch Programmer) during the period 1985- 1990. ▪ Python 3.9.2 is current version Guido van Rossum Inventor of Python
  • 4. Interesting facts about Python Programming 1. Python was a hobby project 2. Why it was called Python [The language’s name isn’t about snakes, but about the popular British comedy troupe Monty Python] 3. Flavors of Python Python ships in various flavors: • CPython- Written in C, most common implementation of Python • Jython- Written in Java, compiles to bytecode • IronPython- Implemented in C#, an extensibility layer to frameworks written in .NET • Brython- Browser Python, runs in the browser • RubyPython- Bridge between Python and Ruby interpreters • PyPy- Implemented in Python • MicroPython- Runs on a microcontroller
  • 5.
  • 6. Scope of learning Python in the field of Mathematics: ▪ Data Analytics ▪ Big Data ▪ Data Mining
  • 7. ▪ https://solarianprogrammer.com/2017/02/25/install-numpy-scipy-matplotlib-python-3 ( To install packages) ▪ windows/https://www.w3schools.com/python/default.asp ▪ https://www.tutorialspoint.com/python/python_environment.htm ▪ https://www.udemy.com/course/math-with-python/ (Cover picture) ▪ https://data-flair.training/blogs/python-career-opportunities/ (companies using python picture) ▪ https://geek-university.com/python/add-python-to-the-windows-path/ (To set path) ▪ https://www.programiz.com/python-programming/if-elif-else
  • 9.
  • 10.
  • 11.
  • 12. Basic Python Learning Exercise 1: To print a message using Python IDE Syntax: print ( “ Your Message”) Example code: print (“Hello, I like Python coding”)# Displays the message in next line # Comments
  • 13. Variables 13 ▪ Variables are nothing but reserved memory locations to store values. ▪ We are declaring a variable means some memory space is being reserved. ▪ In Python there is no need of declaring variables explicitly, if we assign a value it , automatically gets declared. Example: counter = 100 # An integer assignment miles =1000.0 # A floating point name =(“John”) # A string print counter print miles print name
  • 14. Rules to Name Variables ▪ Variable name must always start with a letter or underscore symbol i.e, _ ▪ It may consist only letters, numbers or underscore but never special symbols like @, $,%,^,* etc.. ▪ Each variable name is case sensitive Good Practice : file file123 file_name _file Bad Practice : file.name 12file #filename
  • 15. Types of Operators Operator Type Operations Involved Arithmetic Operator + , - , * , / , % , ** Comparison/ Relational Operator == , != , < , > , <= , >= Assignment Operator = , += , - =, *=, /=, %=, ** = Logical Operator and, or , not Identity Operator is , isnot
  • 16. Operators Precedence Rule Operator Symbol Operator Name ( ) Parenthesis ** Exponentiation (raise to the power) * / % Multiplication , Division and Modulus(Remainder) + - Addition and Subtraction << >> Left to Right
  • 17. Let a = 10 and b = 20 Python Arithmetic Operators
  • 21. CONDITIONAL STATEMENTS One-Way Decisions Syntax: if expression: statement(s) Program: a = 33 b = 35 if b > a: print("b is greater than a") Indentation Python relies on indentation (whitespace at the beginning of a line) to define scope in the code. Other programming languages often use curly-brackets for this purpose.
  • 22. Two-way Decisions Syntax: if expression: statement(s) Else or elif: statement(s) Program: a = 33 b = 33 if b > a: print("b is greater than a") elif a == b: print("a and b are equal")
  • 23. Multi-way if Syntax: if expression1: statement(s) if expression2: statement(s) elif expression3: statement(s) elif expression4: statement(s) else: statement(s) else: statement(s) Program: a = 200 b = 33 if b > a: print("b is greater than a") elif a == b: print("a and b are equal") else: print("a is greater than b")
  • 24. LOOPS AND ITERATION Repeated Steps Syntax: While expression: Body of while Program: count = 0 while (count < 3): count = count + 1 print("Hello all")
  • 25. For Loop Syntax: for val in sequence: Body of for Program: fruits = ["apple", "banana", "cherry"] for x in fruits: print(x) Looking at in: • The iteration variable "iterates through the sequence (ordered set) • The block (body) of code is executed once for each value in the sequence • The iteration variable moves through all the values in the sequence
  • 26. The range() function The range() function returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and ends at a specied number. Program 1: x = range(6) for n in x: print(n) Program 2: x = range(2,6) for n in x: print(n) Program 3: x = range(2,20,4) for n in x: print(n)
  • 27. Quick Overview of Plotting in Python https://matplotlib.org/ Use the command prompt to install the following: ✓ py -m pip install ✓ py -m pip install matplotlib pip is a package management system used to install and manage software packages written in Python.
  • 28. import matplotlib.pyplot as plt # line 1 points x1 = [1,2,3] y1 = [2,4,1] # plotting the line 1 points plt.plot(x1, y1, label = "line 1") # line 2 points x2 = [1,2,3] y2 = [4,1,3] # plotting the line 2 points plt.plot(x2, y2, label = "line 2") # naming the x axis plt.xlabel('x - axis') # naming the y axis plt.ylabel('y - axis') # giving a title to my graph plt.title('Two lines on same graph!') # show a legend on the plot plt.legend() # function to show the plot plt.show() Plotting two or more lines on same plot
  • 29. import matplotlib.pyplot as plt # x-coordinates of left sides of bars left = [1, 2, 3, 4, 5] # heights of bars height = [10, 24, 36, 40, 5] # labels for bars tick_label = ['one', 'two', 'three', 'four', 'five'] # plotting a bar chart plt.bar(left, height, tick_label = tick_label, width = 0.8, color = ['red', 'green']) # naming the x-axis plt.xlabel('x - axis') # naming the y-axis plt.ylabel('y - axis') # plot title plt.title('My bar chart!') # function to show the plot plt.show() Bar Chart
  • 30. import matplotlib.pyplot as plt # defining labels activities = ['eat', 'sleep', 'work', 'play'] # portion covered by each label slices = [3, 7, 8, 6] # color for each label colors = ['r', 'y', 'g', 'b'] # plotting the pie chart plt.pie(slices, labels = activities, colors=colors, startangle=90, shadow = True, explode = (0, 0, 0.1, 0), radius = 1.2, autopct = '%1.1f%%') # plotting legend plt.legend() # showing the plot plt.show() Pie-chart
  • 31. # importing the required modules import matplotlib.pyplot as plt import numpy as np # setting the x - coordinates x = np.arange(0, 2*(np.pi), 0.1) # setting the corresponding y - coordinates y = np.sin(x) # potting the points plt.plot(x, y) # function to show the plot plt.show() Plotting curves of given equation: 𝑺𝒊𝒏 𝒙
  • 32. PYTHON FOR EVERYBODY (https://www.python.org/) For More Details: • http://www.pythonlearn.com/ • https://www.py4e.com/lessons