SlideShare a Scribd company logo
Online Workshop on ‘How to develop
Pythonic coding rather than Python
coding – Logic Perspective’
21.7.20 Day 1 session 1
Dr. S.Mohideen Badhusha
Professor/ CSE department
Alva’s Institute Engineering and
Technology
Mijar, Moodbidri, Mangalore
1
2
Basics of
Python Programming
3
To acquire knowledge in basic programming
constructs in Python
To comprehend the concept of functions in Python
To practice the simple problems in programming
constructs and functions in Python
Objectives of the Day 1 session 1
4
Introduction to Python
• Python - a general-purpose,Interpreted,
interactive, object-oriented and high-level
programming language.
• Fastest growing open source Programming
language
• Dynamically typed
• Versatile and can be adapted in DA,
ML,GUI,Software &Web development
• It was created by Guido van Rossum during
1985-1990.
4
5
Python IDEs
• IDLE
• Pycharm
• Spyder
• Thonny
• Atom
• Anaconda -Jupyter Notebook, Ipython
for larger project in different domains.
• Google colab
5
6
6
Anaconda activated Jupyter
notebook/google colab
7
Comment lines
• Single comment line is # comment line
• Multiple comment lines triple single quotes or
triple double quotes ‘’’ or “””
• ‘’’ multiple comment lines
……
…. ‘’’
“““ This is the Program for blah
blah blah.- multiple comment line”””
# This is a program for adding 2 nos
7
8
Multiple Assignment
• You can also assign to multiple names at the
same time.
>>> x, y = 2, 3
>>> x
2
>>> y
3
Swapping assignment in Python
x,y=y,x
8
9
Reserved Words
(these words can’t be used as varibles)
9
and exec Not
as finally or
assert for pass
break from print
class global raise
continue if return
def import try
del in while
elif is with
else lambda yield
10
Indentation and Blocks
• Python doesn't use braces({}) to
indicate blocks of code for class and
function definitions or flow control.
• Blocks of code are denoted by line
indentation, which is rigidly enforced.
• All statements within the block must
be indented the same level
10
11
• Python uses white space and indents
to denote blocks of code
• Lines of code that begin a block end in
a colon:
• Lines within the code block are
indented at the same level
• To end a code block, remove the
indentation
12
Dynamically Typed: Python determines the data types
of variable bindings in a program automatically.
But Python’s not casual about types, it
enforces the types of objects.
“Strongly Typed”
So, for example, you can’t just append an integer to a
string. You must first convert the integer to a string
itself.
x = “the answer is ” # Decides x is bound to a string.
y = 23 # Decides y is bound to an integer.
print (x + y) # Python will complain about this.
print (x + str(y)) # correct
Python data types
13
Conditional Execution
• if and else
if v == c:
#do something based on the
condition
else:
#do something based on v != c
• elif allows for additional branching
if condition:
…...
elif another condition:
… 13
14
# python program for finding greater of two numbers
a=int(input(‘Enter the first number’))
b=int(input(‘Enter the second number’))
if a>b:
print("The greater number is",a)
else:
print("The greater number is",b)
# for satisfying equality condition
if a>b:
print("The greater number is",a)
elif a==b:
print(“both numbers are equal",a)
else:
print(“The greater number is",b)
15
Nested conditionals
One conditional can also be nested within
another. We could have written the three-branch
example like this:
a=int(input(‘Enter the first number’))
b=int(input(‘Enter the second number’))
if a==b:
print(“Both the numbers are equal",a)
else:
if a>b:
print(“The greater number is",a)
else:
print(“The greater number is",b)
16
Variables, expressions, and statements
python
>>> print(4)
4
If you are not sure what type a value has, the
interpreter can tell you.
>>> type('Hello, World!')
<class 'str'>
>>> type(17)
<class 'int'>
>>> type(3.2)
<class 'float'>
>>> type('17')
<class 'str'>
>>> type('3.2')
<class 'str'>
17
If you give a variable an illegal name, you get
a syntax error:
>>> 76trombones = 'big parade'
SyntaxError: invalid syntax
>>> more@ = 1000000
SyntaxError: invalid syntax
>>> class = 'Advanced Theoretical Zymurgy'
SyntaxError: invalid syntax
18
Operators and operands
a=20 b=10
+ Addition Adds values on either side of the
operator.
a + b = 30
- Subtraction Subtracts right hand operand from
left hand operand.
a – b = -10
* Multiplication Multiplies values on either side of
the operator
a * b = 200
/ Division Divides left hand operand by right hand
operand
b / a = 0.5
19
// Floor Division - The division of operands where the result
is the quotient in which the digits after the decimal point
are removed.
9//2 = 4 and 9.0//2.0 = 4.0
% Modulus Divides left hand operand by right hand
operand and returns remainder
a % b = 0
** Exponent Performs exponential power calculation on
operators
a**b =20 to the power 10
20
Relational Operators
== equal to
!= or <> not equal to
> greater than
>=greater than or equal to
< less than
<= less than or equal to
21
Python Assignment Operators
= Assigns values from right side operands
to left side operand c = a + b assigns value of a + b into c
+= Add AND It adds right operand to the left operand
and assign the result to left operand
c += a is equivalent to c = c + a
-= Subtract AND It subtracts right operand from the left
operand and assign the result to left operand c -= a is
equivalent to c = c – a
*= Multiply AND It multiplies right operand with the left
operand and assign the result to left operand c *= a is
equivalent to c = c * a
22
/= Divide AND It divides left operand with the right
operand and assign the result to left operand c /= a is
equivalent to c = c / ac /= a is
equivalent to c = c / a
%= Modulus AND It takes modulus using two operands
and assign the result to left operand c %= a is
equivalent to c = c % a
**= Exponent Performs exponential power calculation on
operators and assign value to the left c **= a is
equivalent to c = c ** a
23
The + operator works with strings, but it is not addition
in the mathematical sense.
Instead it performs concatenation, which means joining
the strings by linking them end to end. For example:
>>> first = 10
>>> second = 15
>>> print(first+second)
25
>>> first = '100'
>>> second = '150'
>>> print(first + second)
100150
24
Functions
A function is a block of organized, reusable
code that is used to perform a single,
related action.
Functions provide better modularity for
your application and a high degree of code
reusing.
25
Syntax for function definition
def functionname( parameters ):
function_suite
return [expression]
Example :
def great2(x,y) :
if x > y :
return x
else:
return y
Special feature of function in Python is that it can return
more than one value
26
Calling the Function
def great2(x,y) :
if x > y :
return x
else:
return y
a=int(input(‘Enter a’))
b=int(input(‘Enter b’))
print(‘The greater number is’, great2(a,b))
27
Catching exceptions using try and except
inp = input('Enter Fahrenheit Temperature:')
try:
fahr = float(inp)
cel = (fahr - 32.0) * 5.0 / 9.0
print(cel)
except:
print('Please enter a valid number')
28
Concluding Tips
Interpreted ,Object oriented and open sourced
Programming language
Developed by Guido van Rossum during 1985-90
Dynamically typed but strongly typed language
Indented language which has no block level symbols {}
No ; is necessary . Block beginning starts with :
function starts with def key word followed by function
name and :
#- single comment line ’’’ or ””” - multiple comment line
if...else if...elif ...elif No endif
Multiple assignment x,y,z=2,4,5 is possible
/ - divide with precision //- floor division (no precision)

More Related Content

Similar to ‘How to develop Pythonic coding rather than Python coding – Logic Perspective’ (20)

Python-review1 for begineers to code.ppt
Python-review1 for begineers to code.pptPython-review1 for begineers to code.ppt
Python-review1 for begineers to code.ppt
freyjadexon608
 
Python-review1.pdf
Python-review1.pdfPython-review1.pdf
Python-review1.pdf
paijitk
 
Welcome to python workshop
Welcome to python workshopWelcome to python workshop
Welcome to python workshop
Mukul Kirti Verma
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
Mohd Aves Malik
 
Introduction to Python For Diploma Students
Introduction to Python For Diploma StudentsIntroduction to Python For Diploma Students
Introduction to Python For Diploma Students
SanjaySampat1
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 
python_module_.................................................................
python_module_.................................................................python_module_.................................................................
python_module_.................................................................
VaibhavSrivastav52
 
PE1 Module 2.ppt
PE1 Module 2.pptPE1 Module 2.ppt
PE1 Module 2.ppt
balewayalew
 
Presentation1 (1).pptx
Presentation1 (1).pptxPresentation1 (1).pptx
Presentation1 (1).pptx
BodapatiNagaeswari1
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
snowflakebatch
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
Sushant Mane
 
Sessisgytcfgggggggggggggggggggggggggggggggg
SessisgytcfggggggggggggggggggggggggggggggggSessisgytcfgggggggggggggggggggggggggggggggg
Sessisgytcfgggggggggggggggggggggggggggggggg
pawankamal3
 
Introduction-to-Python-Programming1.pptx
Introduction-to-Python-Programming1.pptxIntroduction-to-Python-Programming1.pptx
Introduction-to-Python-Programming1.pptx
vijayalakshmi257551
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming language
Megha V
 
Python ppt
Python pptPython ppt
Python ppt
GoogleDeveloperStude2
 
Python Module-1.1.pdf
Python Module-1.1.pdfPython Module-1.1.pdf
Python Module-1.1.pdf
4HG19EC010HARSHITHAH
 
Learn about Python power point presentation
Learn about Python power point presentationLearn about Python power point presentation
Learn about Python power point presentation
omsumukh85
 
funadamentals of python programming language (right from scratch)
funadamentals of python programming language (right from scratch)funadamentals of python programming language (right from scratch)
funadamentals of python programming language (right from scratch)
MdFurquan7
 
Python-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxPython-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptx
muzammildev46gmailco
 
Python-review1 for begineers to code.ppt
Python-review1 for begineers to code.pptPython-review1 for begineers to code.ppt
Python-review1 for begineers to code.ppt
freyjadexon608
 
Python-review1.pdf
Python-review1.pdfPython-review1.pdf
Python-review1.pdf
paijitk
 
Introduction to Python For Diploma Students
Introduction to Python For Diploma StudentsIntroduction to Python For Diploma Students
Introduction to Python For Diploma Students
SanjaySampat1
 
Python Basics by Akanksha Bali
Python Basics by Akanksha BaliPython Basics by Akanksha Bali
Python Basics by Akanksha Bali
Akanksha Bali
 
python_module_.................................................................
python_module_.................................................................python_module_.................................................................
python_module_.................................................................
VaibhavSrivastav52
 
PE1 Module 2.ppt
PE1 Module 2.pptPE1 Module 2.ppt
PE1 Module 2.ppt
balewayalew
 
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
 
Introduction To Programming with Python
Introduction To Programming with PythonIntroduction To Programming with Python
Introduction To Programming with Python
Sushant Mane
 
Sessisgytcfgggggggggggggggggggggggggggggggg
SessisgytcfggggggggggggggggggggggggggggggggSessisgytcfgggggggggggggggggggggggggggggggg
Sessisgytcfgggggggggggggggggggggggggggggggg
pawankamal3
 
Introduction-to-Python-Programming1.pptx
Introduction-to-Python-Programming1.pptxIntroduction-to-Python-Programming1.pptx
Introduction-to-Python-Programming1.pptx
vijayalakshmi257551
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming language
Megha V
 
Learn about Python power point presentation
Learn about Python power point presentationLearn about Python power point presentation
Learn about Python power point presentation
omsumukh85
 
funadamentals of python programming language (right from scratch)
funadamentals of python programming language (right from scratch)funadamentals of python programming language (right from scratch)
funadamentals of python programming language (right from scratch)
MdFurquan7
 
Python-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptxPython-Certification-Training-Day-1-2.pptx
Python-Certification-Training-Day-1-2.pptx
muzammildev46gmailco
 

More from S.Mohideen Badhusha (7)

Introduction to Python Data Analytics.pdf
Introduction to Python Data Analytics.pdfIntroduction to Python Data Analytics.pdf
Introduction to Python Data Analytics.pdf
S.Mohideen Badhusha
 
Simple intro to HTML and its applications
Simple intro to HTML and its applicationsSimple intro to HTML and its applications
Simple intro to HTML and its applications
S.Mohideen Badhusha
 
PHP Programming and its Applications workshop
PHP Programming and its Applications workshopPHP Programming and its Applications workshop
PHP Programming and its Applications workshop
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Object oriented Programming using C++ and Java
Object oriented Programming using C++ and JavaObject oriented Programming using C++ and Java
Object oriented Programming using C++ and Java
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Introduction to Python Data Analytics.pdf
Introduction to Python Data Analytics.pdfIntroduction to Python Data Analytics.pdf
Introduction to Python Data Analytics.pdf
S.Mohideen Badhusha
 
Simple intro to HTML and its applications
Simple intro to HTML and its applicationsSimple intro to HTML and its applications
Simple intro to HTML and its applications
S.Mohideen Badhusha
 
PHP Programming and its Applications workshop
PHP Programming and its Applications workshopPHP Programming and its Applications workshop
PHP Programming and its Applications workshop
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Object oriented Programming using C++ and Java
Object oriented Programming using C++ and JavaObject oriented Programming using C++ and Java
Object oriented Programming using C++ and Java
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Ad

Recently uploaded (20)

SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
IOt Based Research on Challenges and Future
IOt Based Research on Challenges and FutureIOt Based Research on Challenges and Future
IOt Based Research on Challenges and Future
SACHINSAHU821405
 
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
BeHappy728244
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Mohamed905031
 
FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.
maldonadocesarmanuel
 
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
SharinAbGhani1
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank
Guru Nanak Technical Institutions
 
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete ColumnsAxial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Journal of Soft Computing in Civil Engineering
 
The first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptxThe first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptx
Mayank Mathur
 
MODULE 6 - 1 VAE - Variational Autoencoder
MODULE 6 - 1 VAE - Variational AutoencoderMODULE 6 - 1 VAE - Variational Autoencoder
MODULE 6 - 1 VAE - Variational Autoencoder
DivyaMeenaS
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought                           .社内勉強会資料_Chain of Thought                           .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
Journal of Soft Computing in Civil Engineering
 
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra OpticaPruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
OmarAlfredoDelCastil
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
IOt Based Research on Challenges and Future
IOt Based Research on Challenges and FutureIOt Based Research on Challenges and Future
IOt Based Research on Challenges and Future
SACHINSAHU821405
 
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
BeHappy728244
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Numerical Investigation of the Aerodynamic Characteristics for a Darrieus H-t...
Mohamed905031
 
FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.FISICA ESTATICA DESING LOADS CAPITULO 2.
FISICA ESTATICA DESING LOADS CAPITULO 2.
maldonadocesarmanuel
 
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
02 - Ethics & Professionalism - BEM, IEM, MySET.PPT
SharinAbGhani1
 
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghjfHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
fHUINhKG5lM1WBBk608.pptxfhjjhhjffhiuhhghj
yadavshivank2006
 
The first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptxThe first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptx
Mayank Mathur
 
MODULE 6 - 1 VAE - Variational Autoencoder
MODULE 6 - 1 VAE - Variational AutoencoderMODULE 6 - 1 VAE - Variational Autoencoder
MODULE 6 - 1 VAE - Variational Autoencoder
DivyaMeenaS
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought                           .社内勉強会資料_Chain of Thought                           .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra OpticaPruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
OmarAlfredoDelCastil
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Ad

‘How to develop Pythonic coding rather than Python coding – Logic Perspective’

  • 1. Online Workshop on ‘How to develop Pythonic coding rather than Python coding – Logic Perspective’ 21.7.20 Day 1 session 1 Dr. S.Mohideen Badhusha Professor/ CSE department Alva’s Institute Engineering and Technology Mijar, Moodbidri, Mangalore 1
  • 3. 3 To acquire knowledge in basic programming constructs in Python To comprehend the concept of functions in Python To practice the simple problems in programming constructs and functions in Python Objectives of the Day 1 session 1
  • 4. 4 Introduction to Python • Python - a general-purpose,Interpreted, interactive, object-oriented and high-level programming language. • Fastest growing open source Programming language • Dynamically typed • Versatile and can be adapted in DA, ML,GUI,Software &Web development • It was created by Guido van Rossum during 1985-1990. 4
  • 5. 5 Python IDEs • IDLE • Pycharm • Spyder • Thonny • Atom • Anaconda -Jupyter Notebook, Ipython for larger project in different domains. • Google colab 5
  • 7. 7 Comment lines • Single comment line is # comment line • Multiple comment lines triple single quotes or triple double quotes ‘’’ or “”” • ‘’’ multiple comment lines …… …. ‘’’ “““ This is the Program for blah blah blah.- multiple comment line””” # This is a program for adding 2 nos 7
  • 8. 8 Multiple Assignment • You can also assign to multiple names at the same time. >>> x, y = 2, 3 >>> x 2 >>> y 3 Swapping assignment in Python x,y=y,x 8
  • 9. 9 Reserved Words (these words can’t be used as varibles) 9 and exec Not as finally or assert for pass break from print class global raise continue if return def import try del in while elif is with else lambda yield
  • 10. 10 Indentation and Blocks • Python doesn't use braces({}) to indicate blocks of code for class and function definitions or flow control. • Blocks of code are denoted by line indentation, which is rigidly enforced. • All statements within the block must be indented the same level 10
  • 11. 11 • Python uses white space and indents to denote blocks of code • Lines of code that begin a block end in a colon: • Lines within the code block are indented at the same level • To end a code block, remove the indentation
  • 12. 12 Dynamically Typed: Python determines the data types of variable bindings in a program automatically. But Python’s not casual about types, it enforces the types of objects. “Strongly Typed” So, for example, you can’t just append an integer to a string. You must first convert the integer to a string itself. x = “the answer is ” # Decides x is bound to a string. y = 23 # Decides y is bound to an integer. print (x + y) # Python will complain about this. print (x + str(y)) # correct Python data types
  • 13. 13 Conditional Execution • if and else if v == c: #do something based on the condition else: #do something based on v != c • elif allows for additional branching if condition: …... elif another condition: … 13
  • 14. 14 # python program for finding greater of two numbers a=int(input(‘Enter the first number’)) b=int(input(‘Enter the second number’)) if a>b: print("The greater number is",a) else: print("The greater number is",b) # for satisfying equality condition if a>b: print("The greater number is",a) elif a==b: print(“both numbers are equal",a) else: print(“The greater number is",b)
  • 15. 15 Nested conditionals One conditional can also be nested within another. We could have written the three-branch example like this: a=int(input(‘Enter the first number’)) b=int(input(‘Enter the second number’)) if a==b: print(“Both the numbers are equal",a) else: if a>b: print(“The greater number is",a) else: print(“The greater number is",b)
  • 16. 16 Variables, expressions, and statements python >>> print(4) 4 If you are not sure what type a value has, the interpreter can tell you. >>> type('Hello, World!') <class 'str'> >>> type(17) <class 'int'> >>> type(3.2) <class 'float'> >>> type('17') <class 'str'> >>> type('3.2') <class 'str'>
  • 17. 17 If you give a variable an illegal name, you get a syntax error: >>> 76trombones = 'big parade' SyntaxError: invalid syntax >>> more@ = 1000000 SyntaxError: invalid syntax >>> class = 'Advanced Theoretical Zymurgy' SyntaxError: invalid syntax
  • 18. 18 Operators and operands a=20 b=10 + Addition Adds values on either side of the operator. a + b = 30 - Subtraction Subtracts right hand operand from left hand operand. a – b = -10 * Multiplication Multiplies values on either side of the operator a * b = 200 / Division Divides left hand operand by right hand operand b / a = 0.5
  • 19. 19 // Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. 9//2 = 4 and 9.0//2.0 = 4.0 % Modulus Divides left hand operand by right hand operand and returns remainder a % b = 0 ** Exponent Performs exponential power calculation on operators a**b =20 to the power 10
  • 20. 20 Relational Operators == equal to != or <> not equal to > greater than >=greater than or equal to < less than <= less than or equal to
  • 21. 21 Python Assignment Operators = Assigns values from right side operands to left side operand c = a + b assigns value of a + b into c += Add AND It adds right operand to the left operand and assign the result to left operand c += a is equivalent to c = c + a -= Subtract AND It subtracts right operand from the left operand and assign the result to left operand c -= a is equivalent to c = c – a *= Multiply AND It multiplies right operand with the left operand and assign the result to left operand c *= a is equivalent to c = c * a
  • 22. 22 /= Divide AND It divides left operand with the right operand and assign the result to left operand c /= a is equivalent to c = c / ac /= a is equivalent to c = c / a %= Modulus AND It takes modulus using two operands and assign the result to left operand c %= a is equivalent to c = c % a **= Exponent Performs exponential power calculation on operators and assign value to the left c **= a is equivalent to c = c ** a
  • 23. 23 The + operator works with strings, but it is not addition in the mathematical sense. Instead it performs concatenation, which means joining the strings by linking them end to end. For example: >>> first = 10 >>> second = 15 >>> print(first+second) 25 >>> first = '100' >>> second = '150' >>> print(first + second) 100150
  • 24. 24 Functions A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.
  • 25. 25 Syntax for function definition def functionname( parameters ): function_suite return [expression] Example : def great2(x,y) : if x > y : return x else: return y Special feature of function in Python is that it can return more than one value
  • 26. 26 Calling the Function def great2(x,y) : if x > y : return x else: return y a=int(input(‘Enter a’)) b=int(input(‘Enter b’)) print(‘The greater number is’, great2(a,b))
  • 27. 27 Catching exceptions using try and except inp = input('Enter Fahrenheit Temperature:') try: fahr = float(inp) cel = (fahr - 32.0) * 5.0 / 9.0 print(cel) except: print('Please enter a valid number')
  • 28. 28 Concluding Tips Interpreted ,Object oriented and open sourced Programming language Developed by Guido van Rossum during 1985-90 Dynamically typed but strongly typed language Indented language which has no block level symbols {} No ; is necessary . Block beginning starts with : function starts with def key word followed by function name and : #- single comment line ’’’ or ””” - multiple comment line if...else if...elif ...elif No endif Multiple assignment x,y,z=2,4,5 is possible / - divide with precision //- floor division (no precision)