SlideShare una empresa de Scribd logo
1 de 33
Descargar para leer sin conexión
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

Más contenido relacionado

La actualidad más candente

CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONCLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONLalitkumar_98
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityAakash Singh
 
Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Raj Naik
 
Object Oriented Programming in Python
Object Oriented Programming in PythonObject Oriented Programming in Python
Object Oriented Programming in PythonSujith Kumar
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Sanjit Shaw
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ pptKumar
 
Operators and Control Statements in Python
Operators and Control Statements in PythonOperators and Control Statements in Python
Operators and Control Statements in PythonRajeswariA8
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C ProgrammingShuvongkor Barman
 

La actualidad más candente (20)

CLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHONCLASS OBJECT AND INHERITANCE IN PYTHON
CLASS OBJECT AND INHERITANCE IN PYTHON
 
Introduction to problem solving in C
Introduction to problem solving in CIntroduction to problem solving in C
Introduction to problem solving in C
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Type Conversion, Precedence and Associativity
Type Conversion, Precedence and AssociativityType Conversion, Precedence and Associativity
Type Conversion, Precedence and Associativity
 
Html Form Controls
Html Form ControlsHtml Form Controls
Html Form Controls
 
Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive
 
Object Oriented Programming in Python
Object Oriented Programming in PythonObject Oriented Programming in Python
Object Oriented Programming in Python
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Threads in python
Threads in pythonThreads in python
Threads in python
 
Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Operators and Control Statements in Python
Operators and Control Statements in PythonOperators and Control Statements in Python
Operators and Control Statements in Python
 
File in C language
File in C languageFile in C language
File in C language
 
Unit VI
Unit VI Unit VI
Unit VI
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 

Similar a 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
 

Similar a 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
 

Último

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
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
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
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
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 

Último (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
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.
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
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)
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 

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