SlideShare une entreprise Scribd logo
1  sur  33
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1Kanchilug
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAMaulik Borsaniya
 
Python course syllabus
Python course syllabusPython course syllabus
Python course syllabusSugantha T
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu SharmaMayank Sharma
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming LanguageR.h. Himel
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Fariz Darari
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An IntroductionSwarit Wadhe
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming LanguageTahani Al-Manie
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on pythonwilliam john
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming LanguageDipankar Achinta
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Edureka!
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonAhmed Salama
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-pythonAakashdata
 

Tendances (20)

Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
 
Python course syllabus
Python course syllabusPython course syllabus
Python course syllabus
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu Sharma
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
Python ppt
Python pptPython ppt
Python ppt
 
Python
PythonPython
Python
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on python
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
 
Python basics
Python basicsPython basics
Python basics
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-python
 

Similaire à Python.pdf

Python programming workshop
Python programming workshopPython programming workshop
Python programming workshopBAINIDA
 
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 WayUtkarsh Sengar
 
Python language data types
Python language data typesPython language data types
Python language data typesHarry Potter
 
Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data typesYoung Alista
 
Python language data types
Python language data typesPython language data types
Python language data typesLuis Goldster
 
Python language data types
Python language data typesPython language data types
Python language data typesTony Nguyen
 
Python language data types
Python language data typesPython language data types
Python language data typesFraboni Ec
 
Python language data types
Python language data typesPython language data types
Python language data typesJames Wong
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 

Similaire à 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 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
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 

Dernier

Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 

Dernier (20)

Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 

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