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)

PPTX
UNIT – 3.pptx for first year engineering
SabarigiriVason
 
PDF
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
PDF
python notes.pdf
RohitSindhu10
 
PDF
python 34💭.pdf
AkashdeepBhattacharj1
 
PPTX
MODULE. .pptx
Alpha337901
 
PPTX
Chapter 2-Python and control flow statement.pptx
atharvdeshpande20
 
PPT
C++ Language
Syed Zaid Irshad
 
PPTX
made it easy: python quick reference for beginners
SumanMadan4
 
PDF
Advanced Web Technology ass.pdf
simenehanmut
 
PPT
introduction to python in english presentation file
RujanTimsina1
 
PPTX
python ppt
EmmanuelMMathew
 
PPTX
Python programing
hamzagame
 
PPTX
2.overview of c#
Raghu nath
 
PPTX
Introduction To Python.pptx
Anum Zehra
 
PPTX
Python knowledge ,......................
sabith777a
 
PDF
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
PPTX
Chapter 3 - Programming in Matlab. aaaapptx
danartalabani
 
PPTX
Python Lecture 2
Inzamam Baig
 
ODP
Python basics
Himanshu Awasthi
 
PPTX
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa Thapa
 
UNIT – 3.pptx for first year engineering
SabarigiriVason
 
pythonQuick.pdf
PhanMinhLinhAnxM0190
 
python notes.pdf
RohitSindhu10
 
python 34💭.pdf
AkashdeepBhattacharj1
 
MODULE. .pptx
Alpha337901
 
Chapter 2-Python and control flow statement.pptx
atharvdeshpande20
 
C++ Language
Syed Zaid Irshad
 
made it easy: python quick reference for beginners
SumanMadan4
 
Advanced Web Technology ass.pdf
simenehanmut
 
introduction to python in english presentation file
RujanTimsina1
 
python ppt
EmmanuelMMathew
 
Python programing
hamzagame
 
2.overview of c#
Raghu nath
 
Introduction To Python.pptx
Anum Zehra
 
Python knowledge ,......................
sabith777a
 
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
Chapter 3 - Programming in Matlab. aaaapptx
danartalabani
 
Python Lecture 2
Inzamam Baig
 
Python basics
Himanshu Awasthi
 
Bikalpa_Thapa_Python_Programming_(Basics).pptx
Bikalpa Thapa
 

More from S.Mohideen Badhusha (7)

PDF
Introduction to Python Data Analytics.pdf
S.Mohideen Badhusha
 
PDF
Simple intro to HTML and its applications
S.Mohideen Badhusha
 
PDF
PHP Programming and its Applications workshop
S.Mohideen Badhusha
 
PDF
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
PDF
Object oriented Programming using C++ and Java
S.Mohideen Badhusha
 
PDF
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
PDF
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Introduction to Python Data Analytics.pdf
S.Mohideen Badhusha
 
Simple intro to HTML and its applications
S.Mohideen Badhusha
 
PHP Programming and its Applications workshop
S.Mohideen Badhusha
 
‘How to develop Pythonic coding rather than Python coding – Logic Perspective’
S.Mohideen Badhusha
 
Object oriented Programming using C++ and Java
S.Mohideen Badhusha
 
‘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’
S.Mohideen Badhusha
 
Ad

Recently uploaded (20)

PPTX
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
PDF
Module - 4 Machine Learning -22ISE62.pdf
Dr. Shivashankar
 
PPTX
Alan Turing - life and importance for all of us now
Pedro Concejero
 
PPTX
Engineering Quiz ShowEngineering Quiz Show
CalvinLabial
 
PDF
Digital water marking system project report
Kamal Acharya
 
PDF
Artificial intelligence,WHAT IS AI ALL ABOUT AI....pdf
Himani271945
 
PPTX
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
 
PPTX
darshai cross section and river section analysis
muk7971
 
PDF
bs-en-12390-3 testing hardened concrete.pdf
ADVANCEDCONSTRUCTION
 
PPTX
template.pptxr4t5y67yrttttttttttttttttttttttttttttttttttt
SithamparanaathanPir
 
PPTX
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
PDF
PROGRAMMING REQUESTS/RESPONSES WITH GREATFREE IN THE CLOUD ENVIRONMENT
samueljackson3773
 
PDF
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
PDF
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
PPTX
Seminar Description: YOLO v1 (You Only Look Once).pptx
abhijithpramod20002
 
PDF
Artificial Neural Network-Types,Perceptron,Problems
Sharmila Chidaravalli
 
PDF
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
PPTX
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
PDF
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
PPTX
Engineering Quiz ShowEngineering Quiz Show
CalvinLabial
 
OCS353 DATA SCIENCE FUNDAMENTALS- Unit 1 Introduction to Data Science
A R SIVANESH M.E., (Ph.D)
 
Module - 4 Machine Learning -22ISE62.pdf
Dr. Shivashankar
 
Alan Turing - life and importance for all of us now
Pedro Concejero
 
Engineering Quiz ShowEngineering Quiz Show
CalvinLabial
 
Digital water marking system project report
Kamal Acharya
 
Artificial intelligence,WHAT IS AI ALL ABOUT AI....pdf
Himani271945
 
Unit_I Functional Units, Instruction Sets.pptx
logaprakash9
 
darshai cross section and river section analysis
muk7971
 
bs-en-12390-3 testing hardened concrete.pdf
ADVANCEDCONSTRUCTION
 
template.pptxr4t5y67yrttttttttttttttttttttttttttttttttttt
SithamparanaathanPir
 
Introduction to File Transfer Protocol with commands in FTP
BeulahS2
 
PROGRAMMING REQUESTS/RESPONSES WITH GREATFREE IN THE CLOUD ENVIRONMENT
samueljackson3773
 
3rd International Conference on Machine Learning and IoT (MLIoT 2025)
ClaraZara1
 
13th International Conference of Security, Privacy and Trust Management (SPTM...
ijcisjournal
 
Seminar Description: YOLO v1 (You Only Look Once).pptx
abhijithpramod20002
 
Artificial Neural Network-Types,Perceptron,Problems
Sharmila Chidaravalli
 
WD2(I)-RFQ-GW-1415_ Shifting and Filling of Sand in the Pond at the WD5 Area_...
ShahadathHossain23
 
Introduction to Internal Combustion Engines - Types, Working and Camparison.pptx
UtkarshPatil98
 
Module - 5 Machine Learning-22ISE62.pdf
Dr. Shivashankar
 
Engineering Quiz ShowEngineering Quiz Show
CalvinLabial
 
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)