Chapter 9 - Best Coding Practices in Python
- Authors
- Ms. Samavi Salman
- Dr. Rao Muhammad Adeel Nawab
- Supporting Material
Quick Recap
- Quick Recap – Constants in Python
In previous Chapter, I presented
- Algorithm – In Real-world
- In Real-world, an Algorithm is defined as a well-defined, step-by-step procedure (or a set of rules to follow) for completing a specific Real-world Task / Problem
- Algorithmic Thinking
- Algorithmic Thinking is defined as the ability to define complete and correct set of steps to solve a Real-world Task / Problem
- Algorithm – In Computer Programming
- In Computer Programming, an Algorithm is defused as a well-defined, step-by-step procedure, or set of rules to follow (for getting from Input to Output), that allows a Computer to solve a Real-world Task / Problem
- Pseudo Code
- In Computer Programming, Pseudo Code is a formally styled Natural Language (i.e., very close to English) used to write an Algorithm
- Flow Chart
- In Computer Programming, a Flow Chart is defined as a Step-by-Step Graphical Representation of an Algorithm
Coding Standards
- Practice vs Standard Practice vs Best Practice
- Practice
- Practice is defined as performing (an activity) or exercising (a skill) repeatedly on daily basis in order to acquire, improve or maintain proficiency in it
- Standard
- Standard is defined as a level of quality or attainment
- Standard Practice
- Standard Practice is defined as something that is normally performed in a particular situation with a certain level of quality
- Best Practice
- Best Practice is defined as the commercial or professional procedures that are accepted or prescribed as being correct or most effective
- Standardization
- Definition
- process of making something conform to a Standard
- Purpose
- The main goal of Standardization is to
- enforce a level of consistency or uniformity to certain practices or operations within the selected environment
- The main goal of Standardization is to
- Importance
- Standardization ensures that certain goods or performances are
- produced in the same way via set guidelines
- Standardization ensures that certain goods or performances are
- Applications
- Standardization helps us to
- Improve quality
- Increase productivity
- Increase morale
- Reduce cost
- Save time and effort
- Bring innovation
- Spread knowledge
- Standardization helps us to
- Example – Standardization
- In the whole world, the size of different types of SIMs is same
- Size of Mini SIM
- 2FF
- Size of Micro SIM
- 3FF
- Size of Nano SIM
- 4FF
- Size of Mini SIM
- Coding Standards
- Definition
- Coding Standards are collections of Coding rules, guidelines, and best practices
- Purpose
- The main goal of Coding Standards is to ensure that
- All Programmers writing the Code in a particular Programming Language write according to the guidelines specified
- The main goal of Coding Standards is to ensure that
- Importance
- Coding Standards help us to
- Provide consistency in the Code
- Write Code with less errors
- Make the Code easy to understand, modify, debug and maintain
- Reduce cost, effort and time
- Improve overall quality of the Software
- Coding Standards help us to
- Coding Standards
Java Programming Language – Coding Standards
- The Coding Standards Manual for Java Programming Language can be downloaded from the following link
C Programming Language – Coding Standards
- The Coding Standards Manual for C Programming Language can be downloaded from the following link
PHP Programming Language – Coding Standards
- The Coding Standards Manual for PHP Programming Language can be downloaded from the following link
HTML – Coding Standards
- The Coding Standards Manual for HTML can be downloaded from the following link
TODO and Your Turn
TODO Task 1
- Task
- Consider the following three Real-world Objects and answer the questions given below
- Door (Normal Size)
- Fridge (Normal Size)
- Air Conditioner (1.5 Ton)
- Consider the following three Real-world Objects and answer the questions given below
- Note
- Your answers should be
- Well Justified
- Your answers should be
- Questions
- What are the Standard Length and Width of the above-mentioned Real-world Objects?
- What will be the main advantage of having Standard Length and Width of the above-mentioned Real-world Objects?
Your Turn Task 1
- Task
- Select any three Real-world Objects (similar to the ones given in the TODO) and answer the questions given below
- Note
- Your answers should be
- Well Justified
- Your answers should be
- Questions
- What are the Standard Length and Width of the selected Real-world Objects?
- What will be the main advantage of having Standard Length and Width of the selected Real-world Objects?
Best Practices to Write High Quality Code
- Best Practices to Write High Quality Code
- The main Best Practices that a Programmer should follow in writing high quality Code are as follows
- Commenting and Documentation
- Consistency in Coding Style
- Consistency in Indentation Style
- Consistency in Naming Scheme / Convention
- Data and Code Organization
- File and Folder Organization
- Code Grouping
- Exception Handling
Commenting and Documentation
- Comments
- Definition
- Comments are text notes added to a Program to provide explanatory information about the Source Code
- Note
- Comments are non-executable statements
- i.e., When you execute / run a Program, Comments are ignored by the Compiler / Interpreter / Assembler
- Comments are non-executable statements
- Purpose
- The main purpose of Comments is that
- any Programmer can completely and correctly understand the Program, without taking help from the Programmer who wrote the Program
- The main purpose of Comments is that
- Importance
- Comments help us to improve the
- Overall quality of Source Code
- Readability and understandability of the Source Code
- Comments help us to improve the
- Applications
- Programs that are properly commented are easy to
- read
- understand
- modify / update
- debug
- maintain
- Programs that are properly commented are easy to
- Strengths
- Comments communicate to other Programmers what the Source Code should be doing
- Comments show respect for the next Programmer to read your Source Code
- Comments indicate potential problem areas that should be avoided
Types of Comments
- Example 1 – Single-line Comment in Python
The following Code shows a Single-line Comment in Python for two Python Statements
# Take two Integer Variables as Input from User
number1 = int(input("Enter first Integer: "))
number2 = int(input("Enter second Integer: "))
- Example 2 – Single-line Comment in Python
The following Code shows a Single-line Comment in Python for one Python Statement
# Display "Allah is One" on Output Screen using function: print()
print("Allah is One")
- Multi-line Comment
- Definition
- Multi-line Comment allows narrative on multiple lines at a time
- Suitable to Use
- In practice, it is suitable to use Multi-line Comment if the length of Comment is
- more than 70 characters
- In practice, it is suitable to use Multi-line Comment if the length of Comment is
- Multi-line Comments in Python
- In Python, a Multi-line Comment
- Starts with ”’ Symbol
- Ends with ”’ Symbol
- In Python, a Multi-line Comment
- Example 1 – Multi-line Comment in Python
The following Code shows a Multi-line Comment in Python for one Python Statement
'''The main purpose of this program is to display the message, "Hazrat Muhammad S.A.W.W. is the last Messenger of Allah", on Output Screen using the Python function: print()
'''
print("Hazrat Muhammad S.A.W.W. is the last Messenger of Allah")
Best Practices for Comments
- Best Practices for Comments
- Some of the Best Practices in Commenting Code are as follows
- Comment your Code
- i.e., when writing your Code, also Comment your Code
- After completing the Coding (with proper Comments), again go through the entire Code (and Comments) and
- Check the quality of Comments
- Comments should be of high quality and self-explanatory
- i.e., anyone can understand your Code without taking any help from you
- Be consistent in the use of Commenting Style
- i.e., Use only one Commenting Style in all the Comments
- Comment your Code
- Before writing Comments of Code, your Comments should present the
- Copyright Information
- Authorship Information
- Main purpose of the Program
- Comments should be short, simple and easy to understand
- Comments should not mix up with the Code
- Best Practices for Comments Cont….
- Question
- How can we judge the quality of Comments?
- Answer
- If (A Code is Commented using Best Practices)
- quality
Then
Comments are of high quality
Else
Comments are not of high quality
- TIP
- To become a great and characterful personality
- Never ever compromise on Quality
- There is a famous quote
- If Wealth is lost, Nothing is lost
- If Health is lost, Something is lost
- If Character is lost, Everything is lost
- Always Remember
- To do a great work, first you need to have a great Character
- All great people in the world had a great Character
- Example 1 – Best Practices for Comments
- Given
- Consider the Python Program, which takes two Integer Variables as Input from the User, calculates the sum and display the result on Output Screen?
- Commenting Style
- Inline Comments
- Task
- Evaluate the quality of Comments
'''
The main purpose of this Program is to take two Integer Variables as input from User, calculate the sum and display the result on Output Screen
'''
number1=int(input("Enter first number: ") # Take 'number1' as input from User
number2= int(input("Enter second number: ") # Taking 'number2' as input from User
sum= number1+number2 # Adding two numbers to display sum of Integer Variables in python
print("The sum of Integers is: ", sum) # display sum of two Integer Variables to print sum of two numbers in python
- Remarks
- Very Bad Comments
- Reasons
- Comments are of very poor quality because the following Best Practices are not followed in writing Comments
- Copyright Information is missing
- Authorship Information is missing
- Main Purpose of the Program is missing
- Comments are not simple
- Comments are not short
- Comments are not easy to understand
- Comments are mixing up with the Code
- Comments are not of high quality and self-explanatory
- Example 2 – Best Practices for Comments
- Given
- Consider the Python Program, which takes two Integer Variables as Input from the User, calculates the sum and display the result on Output Screen?
- Commenting Style
- Inline Comments
- Task
- Evaluate the quality of Comments
'''
The main purpose of this Program is to take two Integer Variables as input from User, calculate the sum and display the result on Output Screen
'''
# Take two Integer Variables as input from User
number1 = int(input("Enter first number: ")
number2 = int(input("Enter second number: ")
# Calculate the sum of 'number1' and 'number2'
sum = number1 + number2
# Display sum to User on Output Screen
print("The sum of Integers is: ", sum)
- Remarks
- Bad Comments
- Reasons
- Comments are of poor quality because the following Best Practices are not followed in writing Comments
- Copyright Information is missing
- Authorship Information is missing
- Main Purpose of the Program is missing
- Example 3 – Best Practices for Comments
- Given
- Consider the Python Program, which takes two Integer Variables as Input from the User, calculates the sum and display the result on Output Screen?
- Commenting Style
- Inline Comments
- Task
- Evaluate the quality of Comments
'''
__author__ = Ms. Samavi Salman
__copyright__= Copyright (C) 2020 Ms. Samavi Salman
__license__ = Public Domain
__version__ = 1.0
'''
'''
The main purpose of this Program is to take two Integer Variables as input from a User, calculate the sum and display the result on Output Screen
'''
# Take two Integer Variables as input from User
number1 = int(input("Enter first number: ")
number2 = int(input("Enter second number: ")
# Calculate the sum of 'number1' and 'number2'
sum = number1 + number2
# Display sum to User on Output Screen
print("The sum of Integers is: ", sum)
- Remarks
- Good Comments
- Reasons
- Comments are of good quality because they are written by following the Best Practices 😊
Software Documentation
- Software Documentation
- Definition
- Any written text, illustrations or video that describes a Software to its Users is called Software Documentation (or Program Documentation)
- Note
- User reading the Software Documentation can be a
- Programmer
- System Analyst
- Administrator
- End User
- User reading the Software Documentation can be a
- Purpose
- The main purpose of Software Documentation is to
- facilitate the Software Development Process and
- describe the Software to the Users
- The main purpose of Software Documentation is to
- Importance
- A big Software is normally broken into different modules and there is a separate team for each module
- Good and detailed Software Documentation helps
- Programmers of a module to easily understand the Code written by Programmers of other modules
- Users to easily understand the Code
- Advantages
- Good and detailed Software Documentation helps us to
- Keep track of all modules of a Software
- Reduce the overall cost, effort and time
- Easily understand, modify / update, debug and maintain a Software
- Train the End Users
- Good and detailed Software Documentation helps us to
- Guidelines for Creating High Quality Software Documentation
- To produce high quality Software Documentation some of the main guidelines are as follows
- Software Documentation should be
- complete and correct
- Software Documentation should be written from the
- point of view of the reader
- Software Documentation should follow the
- industry standards
- Software Documentation should be
- Comments vs Software Documentation
- Comments are part of Software Documentation 😊
TODO and Your Turn
TODO Task 1
- Task
- Consider the following six Python Programs and answer the questions given below
- Note
- Your answer should be
- Well Justified
- Your answer should be
- Questions
- Write your Remarks about quality of Comments in the Python Programs
- Possible Remarks are
- Very Bad
- Bad
- Good
- Write Reasons of your Remarks
- Possible Remarks are
- Write your Remarks about quality of Comments in the Python Programs
Python Program 1 |
”’ __author__ = Ms. Samavi Salman __copyright__= Copyright (C) 2020 Ms. Samavi Salman __license__ = Public Domain __version__ = 1.0 ”’
”’ The main purpose of this program is to take an Integer Variable as input from the User, calculate the square root of the Variable and display the result on Output Screen ”’
number = int(input(“Enter an integer: “))
square_root = number ** 0.5 print(“Square root of number is: “, square_root) |
Python Program 2 |
”’ The main purpose of this program is to display a List of elements on Output Screen ”’
numbers = [10, 12, 14]
for number in numbers: print(number) |
Python Program 3 |
”’ The main purpose of this Program is to takes two Integer Variables and display which Variable (i.e., ‘number1 or number2’) is greater using function, on Output Screen ”’
def max_number(number1,number2):
if number1 >= number2: return number1 else: return number2
# Call the function by passing function arguments max_number(10,4) |
Python Program 4 |
”’ The main purpose of this program is to take a String Variable and display alphabet at specified index on Output Screen ”’
message = “Obey your Teachers”
# The output will be ‘e’ message[2] |
Python Program 5 |
”’ __author__ = Ms. Samavi Salman __copyright__= Copyright (C) 2020 Ms. Samavi Salman __license__ = Public Domain __version__ = 1.0 ”’
”’ The main purpose of this program is to take a String Variable and display the sum of indexes on Output Screen ”’
message = “Obey your Teachers”
”’ Character at index 2 and character at index 0 will be added along with character at index 8 the output displayed on screen will be ‘eOT’ ”’ sum = message[2] + message[0] + message[8] |
Python Program 6 |
”’ The main purpose of this Program is to take String Variable and display on Output Screen by removing left and right spaces of String ”’
message = ” Do Zikar of Allah on daily basis to achieve excellence in love and friendship of Allah “; message.lstrip() # Remove left space message.rstrip() # Remove right space |
Your Turn Task 1
- Task
- Write Nine Python Programs
- Three should be Very Bad examples of Comments
- Three should be Bad examples of Comments
- Three should be Good examples of Comments
- Write Nine Python Programs
Consistency in Coding Style
- Consistency
- Definition
- Formal Definition
- Consistency is defined as steadfast adherence to the same principles of Character over time
- Purpose
- The main purpose of Consistency is to
- build your ability to hold yourself accountable for the daily choices you make with no excuses and no complaints to achieve the main goal of life i.e.,
- Achieve Excellence in Friendship of Allah
- build your ability to hold yourself accountable for the daily choices you make with no excuses and no complaints to achieve the main goal of life i.e.,
- The main purpose of Consistency is to
- Importance
- Life is Marathon, Not 100 Meters
- To win Marathon, you need
- Consistency and Patience
- Little efforts daily will make you the greatest
- Life is Marathon, Not 100 Meters
- Applications
- To become an authority in any field, you need
- Consistency 😊
- To become an authority in any field, you need
- Consistency in Character
- Example 1
- main() Function calls pakistan() Function
- Calling Function
- main() Function
- Called Function
- pakistan() Function
- Example 2
- india() Function calls pakistan() Function
- Calling Function
- india() Function
- Called Function
- pakistan() Function
- PEP 8 – Official Coding Style Guide for Python
- Definition
- PEP stands for Python Enhancement Proposal
- The PEP 8 is the Style Guide for Python Code and it mainly covers
- Formatting
- Comments
- Naming Scheme / Convention
- Purpose
- The main purpose of PEP 8 is to provide
- Coding Conventions for Python Programming Language to write high quality Code
- The main purpose of PEP 8 is to provide
- Importance
- The PEP 8 coding style guidelines helps us is to improve the
- readability of Python Code
- consistency of Python Code
- The PEP 8 coding style guidelines helps us is to improve the
- Note
- Insha Allah, in the next Slides, I will present, how to bring
- Consistency in Indentation
- Consistency in Naming Scheme / Convention
Consistency in Indentation Style
- Indentation Style
- Definition
- In Computer Programming, an Indentation Style is a convention governing the indentation of blocks of Code to convey Program Structure
- Note
- Python uses Indentation to determine the Program Structure
- Purpose
- The main purpose of Indentation is to make a Program
- easy to read and understand
- The main purpose of Indentation is to make a Program
- Importance
- Indentation is important to increase the overall quality of a Program
- Advantages
- A consistent Indentation Style helps us to easily
- read and understand a Program
- modify, debug and maintain a Program
- A consistent Indentation Style helps us to easily
- Indentation Level in Python
- The Indentation Level of lines of Code in Python determines
- How Python Statements are grouped together
- Standard Indentation Level
- Use 4 consecutive spaces to indicate indentation
- Indentation – Spaces vs Tabs
- Prefer Spaces over Tabs
Best Practices for Indentation
- Best Practices for Indentation
- Below I present Best Practices for Indentation
- Best Practice 1
- Leave a blank Line before starting a new Comment
- Best Practice 1
- Example 1 - Best Practices for Indentation
'''
The main purpose of this Program is to display the following message on Output Screen: "Offer Namaz Five Times a Day"
'''
print("Offer Namaz Five Times a Day")
- Example 2 - Best Practices for Indentation
'''
The main purpose of this Program is to print the value of an Integer Variable on Output Screen
'''
number = 10
print(number)
- Example 3 - Best Practices for Indentation
'''
The main purpose of this program is to take a String Variable as input from the User and display the String on Output Screen
'''
message = input("Enter a message: ")
print(message)
- Best Practices for Indentation Cont…
- Best Practice 2
- There should be a Single Space on Left and Right Side of a Variable / Constant / Operator in a Python Statement
- Best Practice 2
- Example 1 - Best Practices for Indentation
'''
The main purpose of this Program is to perform DMAS (Divide, Multiple, Add, Subtract) Operations and display the result on Output Screen
'''
PI = 3.14
result = 10 + 8 / 2 * PI
print(result)
- Example 2 - Best Practices for Indentation
'''
The main purpose of this Program is to take an Integer Variable and display the value of Variable (called 'number') if it is less than 5 on Output Screen
'''
number = 10
if number > 5:
print(number, " is greater than 5")
- Example 3 - Best Practices for Indentation
'''
The main purpose of this Program is to take an Integer Variable and display the value of Variable (called ‘count’) up-to 3 on Output Screen using Loop
'''
count = 0
while (count < 3):
count = count + 1
print(count)
- Best Practices for Indentation Cont…
- Best Practice 3
- In an if Python Statement, Python Statement(s) after if Condition should be Indented with
- 4 Spaces
- In an if Python Statement, Python Statement(s) after if Condition should be Indented with
- Best Practice 3
- Example 1 - Best Practices for Indentation
'''
The main purpose of this Program is to take a Character as input from User and display whether it’s a vowel or not on Output Screen
'''
vowel = input(“Enter a vowel: “);
if vowel == 'a' || 'e' || 'i' || 'o' || 'u':
print("It is a vowel")
- Example 2 - Best Practices for Indentation
'''
The main purpose of this Program is to take an Integer Variables as input from User, and display whether it’s a Positive Integer, Negative Integer or Zero on Output Screen
'''
number = int(input("Enter an integer number: "))
if number < 0:
if number == 0:
print("Number is ZERO")
else:
print(number, " is a Positive number")
else:
print(number, " is a Negative number")
- Example 3 - Best Practices for Indentation
'''
The main purpose of this Program is to display Even number from 0-10 on Output Screen
'''
for number in range(10):
if number % 2 == 0:
print(number, " is an Even number")
- Best Practices for Indentation Cont…
- Best Practice 4
- In an if-else Python Statement, Python Statement(s) after if Condition and else Python Statement should be Indented with
- 4 Spaces
- In an if-else Python Statement, Python Statement(s) after if Condition and else Python Statement should be Indented with
- Best Practice 4
'''
The main purpose of this Program is to display Even number from 0-10 on Output Screen
'''
for number in range(10):
if number % 2 == 0:
print(number, " is an Even number")
'''
The main purpose of this Program is to display Even number from 0-10 on Output Screen
'''
for number in range(10):
if number % 2 == 0:
print(number, " is an Even number")
- Example 1 - Best Practices for Indentation
'''
The main purpose of this Program is to take a Character as input from User and display whether it’s a vowel or not on Output Screen
'''
vowel = input("Enter a vowel: ")
if vowel == 'a' || 'e' || 'i' || 'o' || 'u':
print("It is a Vowel")
else:
print("It is not a Vowel")
- Example 2 - Best Practices for Indentation
'''
The main purpose of this Program is to take an Integer Variable as input from the User and display whether it's an Even number or Odd number on Output Screen
'''
number = int(input("Enter an integer number: "))
if number % 2 == 0:
print(number, " is an Even number")
elif number % 2 == 1;
print(number, " is an Odd number")
else:
print("Invalid number")
- Example 3 - Best Practices for Indentation
'''
The main purpose of this Program is to take Integer Variable (called 'marks') as input from User and display the grade on Output Screen
'''
marks = int(input("Enter your marks in Introduction to Python course: "))
if marks >= 90:
print("Your grade in Introduction to Python is: A")
elif marks >= 80 and marks <= 90:
print("Your grade in Introduction to Python is: B+")
elif marks >= 70 and marks <= 80:
print("Your grade in Introduction to Python is: B")
elif marks >= 60 and marks <= 70:
print("Your grade in Introduction to Python is: C+")
elif marks >= 50 and marks <= 60:
print("Your grade in Introduction to Python is: C")
else:
print("Your grade in Introduction to Python is: F")
- Best Practices for Indentation Cont…
- Best Practice 5
- In a loop Python Statement, Python Statement(s) after loop Python Statement, should be Indented with
- 4 Spaces
- In a loop Python Statement, Python Statement(s) after loop Python Statement, should be Indented with
- Best Practice 5
- Example 1 - Best Practices for Indentation
'''
The main purpose of this Program is to take a List of element, and display each alphabet of List on Output Screen
'''
alphabets = ['A', 'l', 'l', 'a', 'h']
for alphabet in alphabets:
print(alphabet)
- Example 2 - Best Practices for Indentation
'''
The main purpose of this Program is to print Integers from 1-10 and display the result on Output Screen using Loop
'''
count = 0;
while (count <= 10):
count = count + 1
print("Value of count is: ", count)
- Example 3 - Best Practices for Indentation
'''
The main purpose of this Program is to print Integers from 1-10 and display the result on Output Screen using Loop
'''
start_value = 1
end_value = 10
for number in range(start_value, end_value):
print("/n" , number);
- Best Practices for Indentation Cont…
- Best Practice 6
- In a function Python Statement, Python Statement(s) after function Python Statement should be Indented with
- 4 Spaces
- In a function Python Statement, Python Statement(s) after function Python Statement should be Indented with
- Best Practice 6
- Example 1 - Best Practices for Indentation
'''
The main purpose of this Program is to take String Variables and display the message on Output Screen using Function
'''
def displayMessage(message1, message2):
print("First message: ", message1)
print("Second message: ", message2)
list_values('Respect your Elders',
'Do Zikar of Allah on Daily Basis')
- Example 2 - Best Practices for Indentation
'''
The main purpose of this Program is to take display the message on Output Screen using Function
'''
def DisplayMessage():
print("Allah is the creator of heavens and earth")
print("Allah loves those who love the humanity")
DisplayMessage()
- Example 3 - Best Practices for Indentation
'''
The main purpose of this Program is to take two Integer Variables and display the sum on Output Screen using Function
'''
def function(argument1, argument2):
sum = argument1 + argument2
function(10,20)
- Best Practices for Indentation Cont…
- Best Practice 7
- If a Python Statement is greater than 79 characters then
- Wrapping long lines inside parentheses, brackets and braces
- If a Python Statement is greater than 79 characters then
- Example 1 - Best Practices for Indentation
if (number1 > number2 and
number2 > number3 and
number1 > number3
):
- Example 2 - Best Practices for Indentation
'''
The main purpose of this program is to display the message, "Hazrat Muhammad S.A.W.W. is the last Messenger of Allah", on Output Screen using print() function
'''
- Example 3 - Best Practices for Indentation
months = ['Muharram', 'Safar',
'Rabi-ul-awwal', 'Rabi-ul-Sani',
'Jumada al-awwal', 'Jumada al-Sanil',
'Rajab', 'Shaban',
'Ramadan', 'Shawwal',
'Zikad', 'Zilhajj']
- Best Practices for Indentation Cont…
- Best Practice 8
- Usage of blank spaces
- After Class Definition use double blank spaces
- After Function / Method Definition use single blank space
- Usage of blank spaces
- Best Practice 8
- Example 1 - Best Practices for Indentation
'''
The main purpose of this program is to make a class an assign values to 'name' and 'age'
'''
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
- Example 2 - Best Practices for Indentation
'''
The main purpose of this program is display a String on Output Screen
'''
def Display_Message(str):
print(str)
Display_Message("Always speak the truth")
- Best Practices for Indentation Cont…
- Best Practice 9
- In a Python Program, write one statement per line
- Best Practice 9
- Example 1 - Best Practices for Indentation
'''
The main purpose of this Program is to print a message 5 times along with the count on Output Screen
'''
for count in range(5):
print("Assalam-o-Alaikum")
print("count: ", count)
- Example 2 - Best Practices for Indentation
'''
The main purpose of this Program is to take Integer Variables, calculate their sum and display the result on Output Screen
'''
number1 = 2
number2 = 4
sum = number1 + number2
print("The sum of Integers is: ", sum)
- Example 3 - Best Practices for Indentation
'''
The main purpose of this Program is to take an Integer Variable as input from the User and display whether it’s an Even number or Odd number on Output Screen
'''
number = int(input("Enter an Integer: "))
if number % 2 == 0:
print(number, " is an Even number")
elif number % 2 == 1;
print(number, " is an Odd number")
else:
print(number, " is an invalid number")
- Best Practices for Indentation Cont…
- Best Practice 10
- In an import Python Statements, each import Python Statement should be on a separate line
- Note
- Always put Import Python Statement(s) at the start of the Code
- Best Practice 10
- Example 1 - Best Practices for Indentation
import numpy
import pandas
- Example 2 - Best Practices for Indentation
from subprocess import Popen, PIPE
- Example 3 - Best Practices for Indentation
import numpy as np
import pandas as pd
- Best Practices for Indentation Cont…
- Best Practice 11
- In a Python Statement, use proper White Spaces in expressions and statements
- Best Practice 11
- Example 1 - Best Practices for Indentation
# Correct
number = (0,)
# Wrong
number = (0, )
- Example 2 - Best Practices for Indentation
# Correct
dct['key'] = lst[index]
# Wrong
dct ['key'] = lst [index]
- Example 3 - Best Practices for Indentation
# Correct
if number == 4: print(number)
# Wrong
if number == 4 : print(number)
Best Practices for Indentation
- Best Practices for Indentation
- In the Previous Slides, I identified 11 Best Practices for Indentation, which are as follows
- Best Practice 1
- Leave a Blank Line before Starting a Comment
- Best Practice 2
- There should be a Single Space on Left and Right Side of a Variable / Constant / Operator in a Python Statement
- Best Practice 3
- In an if Python Statement, Python Statement(s) after if Condition should be Indented with
- 4 Spaces
- In an if Python Statement, Python Statement(s) after if Condition should be Indented with
- Best Practice 4
- In an if-else Python Statement, Python Statement(s) after if Condition and else Python Statement should be Indented with
- 4 Spaces
- In an if-else Python Statement, Python Statement(s) after if Condition and else Python Statement should be Indented with
- Best Practice 5
- In a loop Python Statement, Python Statement(s) after loop Python Statement, should be Indented with
- 4 Spaces
- In a loop Python Statement, Python Statement(s) after loop Python Statement, should be Indented with
- Best Practice 6
- In a function Python Statement, Python Statement(s) after function Python Statement should be Indented with
- 4 Spaces
- In a function Python Statement, Python Statement(s) after function Python Statement should be Indented with
- Best Practice 7
- If a Python Statement is greater than 79 characters then Wrapping long lines inside parentheses, brackets and braces
- Best Practice 8
- Usage of blank spaces
- After Class Definition use double blank spaces
- After Function / Method Definition use single blank space
- Best Practice 9
- In a Python Program, write one statement per line
- Best Practice 10
- In an import Python Statements, each import Python Statement should be on a separate line
- Best Practice 11
- In a Python Statement, use proper White Spaces in expressions and statements
- Best Practice 1
- Best Practices for Indentation Cont…
- Insha Allah, in the next Slides, I will present examples of Good and Bad Indentation
- Example 1 – Best Practices for Indentation
- Given
- Consider a Python Program, which take two Integer Variables as Input and checks whether Number1 is less than Number2 or not?
- Task
- Evaluate the quality of Indentation
'''
The main purpose of this Program is to take two Integer Variables, check which Variable is greater and display the result on Output Screen
'''
number1=10;
number2=20;
# check if the "number1" is less than "number2"
if number1
- Remarks
- Very Bad Indentation
- Reasons
- Indentation is of very poor quality because the following Best Practices are not followed while writing the code
- There is no Blank Line before Starting a Comment
- There is no Single Space on Left and Right Side of a Variable / Constant / Operator
- if Condition is not Indented with 4 Spaces
- if-else is not Indented with 4 Spaces
- Multiple statements are written in one line
- Inappropriate White Spaces in expressions and statements
- Indentation is of very poor quality because the following Best Practices are not followed while writing the code
- Example 2 – Best Practices for Indentation
- Given
- Consider a Python Program, which take two Integer Variables as Input and checks whether Number1 is less than Number2 or not?
- Task
- Evaluate the quality of Indentation
'''
The main purpose of this Program is to take two Integer Variables, check which Variable is greater and display the result on Output Screen
'''
number1= 10
number2= 20
# Check if "number1" is less than "number2"
if number1 < number2:
print("Number1 is less than Number2")
else:
print("Number2 is less than Number1")
- Remarks
- Bad Indentation
- Reasons
- Indentation is of poor quality because the following Best Practices are not followed while writing the code
- There is no Blank Line before Starting a Comment
- Inappropriate Single Space on Left and Right Side of a Variable / Constant / Operator
- Inappropriate White Spaces in expressions and statements
- Indentation is of poor quality because the following Best Practices are not followed while writing the code
- Example 3 – Best Practices for Indentation
- Given
- Consider a Python Program, which take two Integer Variables as Input and checks whether Number1 is less than Number2 or not?
- Task
- Evaluate the quality of Indentation
'''
__author__ = Ms. Samavi Salman
__copyright__= Copyright (C) 2020 Ms. Samavi Salman
__license__ = Public Domain
__version__ = 1.0
'''
'''
The main purpose of this Program is to take two Integer Variables, check which Variable is greater and display the result on Output Screen
'''
number1 = 10
number2 = 20
if number1 < number2:
print("Number1 is less than Number2")
else:
print("Number2 is less than Number1")
- Remarks
- Good Indentation
- Reasons
- Indentation is good because Code is written by following the Best Practices 😊
TODO and Your Turn
TODO Task 1
- Task
- Consider the following six Python Programs and answer the questions given below
- Note
- Your answer should be
- Well Justified
- Your answer should be
- Questions
- Write your Remarks about quality of Indentation in the Python Programs
- Possible Remarks are
- Very Bad
- Bad
- Good
- Possible Remarks are
- Write Reasons of your Remarks
- Write your Remarks about quality of Indentation in the Python Programs
Python Program 1 |
”’ The main purpose of this Program is to take an Integer Variable as input from the User, calculate the square root of Variable and display the result on Output Screen ”’ number=int(input(“Enter an integer: “)) square_root= number**0.5 print(“Square root of number is: “, square_root) |
Python Program 2 |
”’ The main purpose of this Program is to print each element of List on Output Screen ”’ numbers =[10, 12, 14] for number in numbers: print(number) |
Python Program 3 |
”’ The main purpose of this Program is to take two Integer Variables and check which number is greater using Function ”’ def max_number(number1,number2): if number1 >= number2: return number1 else: return number2 # Call the function by passing function argument max_number(10,4) |
Python Program 4 |
”’ The main purpose of this Program is to take a String Variable and display the character at specified index ”’ message = “Obey your Teachers” # Character at index 2 will be displayed on screen i.e., ‘e’ message [2] |
Python Program 5 |
”’ The main purpose of this Program is to take a String Variable and display the characters at specified index ”’ message= “Obey your Teachers” # The Output displayed on Screen will be ‘eOT’ sum = message[2] +message[0] +message[8] |
Python Program 6 |
”’ The main purpose of this Program is to take String Variable and remove left and right spaces of String ”’ message = ” Do Zikar Everyday “; message.lstrip() # Remove left space using lstrip() function message.rstrip() # Remove left space using rstrip() function |
Your Turn Task 1
- Task
- Write Nine Python Programs
- Three should be Very Bad examples of Indentation
- Three should be Bad examples of Indentation
- Three should be Good examples of Indentation
- Write Nine Python Programs
Consistency in Naming Scheme / Convention
- Identifier
- Definition
- In Python Programming Language, an Identifier is a name used to identify a variable, function, class, module or other object
- Naming Scheme / Convention for an Identifier
- An Identifier starts with a letter A to Z or a to z or an underscore (_) followed by
- zero or more letters, underscores and digits (0 to 9)
- An Identifier starts with a letter A to Z or a to z or an underscore (_) followed by
- Naming Scheme / Convention
- Definition
- Set of rules for writing Identifiers and other entities in Source Code and Documentation of a Python Program is called Naming Scheme / Convention
- Purpose
- The main purpose of Naming Scheme / Convention is to
- improve the overall quality of the Source Code by making it easy to read and understand
- The main purpose of Naming Scheme / Convention is to
- Importance
- It is important to have a Naming Scheme / Convention to
- write high quality Source Code
- maintain consistency in Code
- easily and quickly understand the Code
- It is important to have a Naming Scheme / Convention to
- Applications
- Code written using a consistent Naming Scheme / Convention can be
- easily documented
- easily understood by the Users and other Programmers
- easily debugged, modified and maintained
- Code written using a consistent Naming Scheme / Convention can be
- Strengths
- Code written using Naming Scheme / Convention improves overall quality of the Code in terms of
- Communication
- Code integration
- Consistency
- Clarity
- Code written using Naming Scheme / Convention improves overall quality of the Code in terms of
- Weaknesses
- Cost of updating an Identifier written using a Naming Scheme / Convention is high
Best Practices Naming Scheme / Convention
- Best Practices for Naming Scheme / Convention
- Below I present Best Practices for Naming Scheme / Convention of
- Variable Name
- Constant Name
- Function Arguments
- Package Name
- Module Name
- Argument of Instance Method
- Argument of Class Method
- Class Name
- Exception Classes
- Use of Underscore
- Variable Name – Best Practices (Naming Scheme / Conventions)
- The Best Practices to write Variable Names are as follows
- Best Practice 1
- Variable Name
- Variable Name should be in lower case
- Variable Name
- Best Practice 1
number1 = int(input("Enter an integer number: "))
-
-
-
- Avoid using single character (x,y,z,l,i) Variable Name
-
-
# Wrong
I = 0
Correct
count = 0
- Use snake case for variable names
display_message = "Strive for progress, not perfection"
OR
DISPLAY_MESSAGE = "Strive for progress, not perfection"
- User underscore to separate words in long Variable Names
display_message = "Push yourself because no one else is going to do it"
- Use expressive Variable Names
# Wrong
I = 0
# Correct
count = 0
- Avoid Variable Names that begin with a number
# Wrong
1number = 10
# Correct
number1 = 10
- Avoid using Special Characters (@,!,#,$) in Variable Names
# Wrong
number!1 = 10
# Wrong
number#1 = 10
# Wrong
number@1 = 10
# Correct
number1 = 10
- Best Practice 2
- Constant Name
- Constants are usually declared and assigned values within a module
- Constant Name
- Best Practice 2
GRAVITY = 9.18
- The Naming Scheme / Convention for Constants is an aberration
PI = 3.14
- Constant Names should be all CAPITAL letters
SPEED_OF_LIGHT = 3 * 10 ** 8
- Best Practice 3
- Function Argument
- If Function Argument Name clashes with keyword use trailing underscore either at the beginning or end of the Name
- Function Argument
- Best Practice 3
def display_message(_int):
- Use meaningful names
def display_phrase():
- The lowercase Naming Scheme / Convention should be followed
def function_name():
- Best Practice 4
- Module Name
- Prefer underscores for long Module Names
- Module Name
- Best Practice 4
import mod # module name
- Best Practice 5
- Package Name
- Avoid underscores for Package Names
- Package Name
- Best Practice 5
mod1.py # package name
OR
import pkg
- Best Practice 6
- Argument of Instance Method
- The first Argument of an Instance Method (the basic Class Method with no strings attached) should always be self
- This points to the Calling Object
- The first Argument of an Instance Method (the basic Class Method with no strings attached) should always be self
- Argument of Instance Method
- Best Practice 6
class SampleClass:
def instance_method(self, del_):
print("It is an instance method")
- Best Practice 7
- Argument of Class Method
- The first argument of a class method should always be cls This points to the class, not the object instance
- Argument of Class Method
class SampleClass:
def class_method(cls):
print("It is a class method")
- Best Practice 8
- Follow CapWord (or camelCase) naming convention. Just start each word with a capital letter and do not include underscores between words
- PEP 8 suggests that you use CamelCase for class definitions
- If a class contains a subclass with the same attribute name, consider adding double underscores to the class attribute
#Camel Case
Class depositeCharges:
class Person:
def __init__(self):
self.__age = 18
obj = Person()
obj.__age # Error
obj._Person__age # Correct
- Best Practice 9
- Exception Classes
- Use the suffix Error for exception classes
- Exception Classes
class ExceptionHandling(Exception):
- Best Practice 10
- Use of Underscore
- Single Leading Underscore _var
- Naming convention indicating name is meant for internal use. A hint for programmers and not enforced by programmers
- Single Leading Underscore _var
- Use of Underscore
class Test:
def __init__(self):
self.number1 = 15
self._number2 = 25
test = Test()
test.number1
test._number2
- Double Leading and Trailing Underscore __var
- Triggers name mangling when used in class context. Enforced by the Python interpreter
- Double Leading and Trailing Underscore __var
class PrefixPostfixTest:
def __init__(self):
self.__number__ = 42
PrefixPostfixTest().__number__
- Single Trailing Underscore var_
- Used by convention to avoid naming conflicts with Python keywords
- Single Trailing Underscore var_
def function_name(name, class_):
pass
- Underscore _
- Used as a name for temporary variables
- Underscore _
'''
The main purpose of this Program is to print ' صلی اللہ علیہ وسلم' thirty two times on Output Screen
'''
for _ in range(32):
print(' صلی اللہ علیہ وسلم')
- Best Practices for Naming Convention
- In the Previous Slides, I identified 6 Best Practices for Naming Scheme / Convention, which are as follows
- Best Practice 1
- Variable Name
- Variable Name should be in lower case
- Avoid using single character (x,y,z,l,i) Variable Name
- Use snake case for Variable Names
- User underscore to separate words in long Variable Names
- Use expressive Variable Names
- Avoid Variable Names that begin with a number
- Avoid using Special Characters (@,!,#,$) in Variable Names
- Variable Name
- Best Practice 2
- Constant Name
- Constants are usually declared and assigned values within a module
- The Naming Scheme / Convention for Constants is an aberration
- Constant Names should be all CAPITAL letters
- Constant Name
- Best Practice 3
- Function Argument
- If Function Argument Name clashes with keyword use trailing underscore either at the beginning or end of the Name
- Use meaningful names
- The lowercase Naming Scheme / Convention should be followed
- Function Argument
- Best Practice 4
- Module Name
- Prefer underscores for long Module Names
- Module Name
- Best Practice 5
- Package Name
- Avoid underscores for Package Names
- Package Name
- Best Practice 6
- Argument of Instance Method
- The first Argument of an Instance Method (the basic Class Method with no strings attached) should always be self
- This points to the Calling Object
- Argument of Instance Method
- Best Practice 1
- Best Practice 7
- Argument of Class Method
- The first argument of a class method should always be cls This points to the class, not the object instance
- Argument of Class Method
- Best Practice 8
- Follow CapWord (or camelCase) naming convention. Just start each word with a capital letter and do not include underscores between words
- PEP 8 suggests that you use CamelCase for class definitions
- If a class contains a subclass with the same attribute name, consider adding double underscores to the class attribute
- Best Practice 9
- Exception Classes
- Use the suffix Error for exception classes
- Exception Classes
- Best Practice 10
- Use of Underscore
- Single Leading Underscore _var
- Naming convention indicating name is meant for internal use. A hint for programmers and not enforced by programmers
- Double Leading and Trailing Underscore __var
- Triggers name mangling when used in class context. Enforced by the Python interpreter
- Underscore _
- Used as a name for temporary variables
- Single Leading Underscore _var
- Use of Underscore
- Best Practices for Indentation Cont…
- Insha Allah, in the next Slides, I will present examples of Good and Bad Naming Scheme / Convention
- Example 1 – Best Practices for Naming Scheme / Convention
- Given
- Consider a Python Program, which take two Integer Variables as Input and display which Variable is greater on Output Screen?
- Task
- Evaluate quality of Naming Scheme / Conventions
'''
The main purpose of this Program is to take two Integer Variables, check which number is greater and display the result on Output Screen
'''
X = int(input("Enter first integer: "))
Y = int(input("Enter second integer: "))
if X > Y:
print("X is greater than Y")
else:
print("Y is greater than X")
- Remarks
- Very Bad Naming Scheme / Convention
- Reasons
- Naming Scheme / Conventions are of very poor quality because the following Best Practices are not followed
- Variable Names are not in lower case
- Variable Name comprises of a single Character
- Variable Names are not expressive
- Naming Scheme / Conventions are of very poor quality because the following Best Practices are not followed
- Example 2 – Best Practices for Naming Scheme / Convention
- Given
- Consider a Python Program, which take two Integer Variables as Input and display which Variable is greater on Output Screen?
- Task
- Evaluate quality in Naming Scheme / Conventions
'''
The main purpose of this Program is to take two Integer Variables, check which number is greater and display the result on Output Screen
'''
Number1 = int(input("Enter first integer: "))
Number2 = int(input("Enter second integer: "))
if Number1 > Number2:
print("Number1 is greater than Number2")
else:
print("Number2 is greater than Number1")
- Remarks
- Bad Naming Scheme / Convention
- Reasons
- Naming Scheme / Convention is of poor quality because the following Best Practices are not followed
- Variable Names are not in lower case
- Variable Names are not expressive
- Naming Scheme / Convention is of poor quality because the following Best Practices are not followed
- Example 3 – Best Practices for Naming Scheme / Convention
- Given
- Consider a Python Program, which passes two Integer Variables as parameters to a function and calculates the sum of Number1 and Number2?
- Task
- Evaluate quality in Naming Scheme / Convention
'''
__author__ = Ms. Samavi Salman
__copyright__= Copyright (C) 2020 Ms. Samavi Salman
__license__ = Public Domain
__version__ = 1.0
'''
'''
The main purpose of this Program is to take two Integer Variables, check which number is greater and display the result on Output Screen
'''
number1 = int(input("Enter first integer: "))
number2 = int(input("Enter second integer: "))
if number1 > number2:
print("Number1 is greater than Number2")
else:
print("Number2 is greater than Number1")
- Remarks
- Good Naming Scheme / Convention
- Reasons
- Naming Scheme / Convention are good because they are written by following the Best Practices 😊
TODO and Your Turn
TODO Task 1
- Task
- Consider the following six Python Programs and answer the questions given below
- Note
- Your answer should be
- Well Justified
- Your answer should be
- Questions
- Write your Remarks about quality of Naming Scheme / Convention in the Python Programs
- Possible Remarks are
- Very Bad
- Bad
- Good
- Possible Remarks are
- Write Reasons of your Remarks
- Write your Remarks about quality of Naming Scheme / Convention in the Python Programs
Python Program 1 |
”’ The main purpose of this Program is to take an Integer Variable as input from the User, calculate the square root and display the result on Output Screen ”’
X = int(input(“Enter an integer: “))
Y = X ** 0.5 print(“Square root of number is: “, Y) |
Python Program 2 |
”’ The main purpose of this Program is to print each element of List on Output Screen ”’
listofnumbersfromUser = [10, 12, 14]
# Iterate the list and display the output on screen for number in listofnumbersfromUser: print(number) |
Python Program 3 |
”’ The main purpose of this Program is to takes two Integer Variables and check which number is greater using function ”’
def max_number(number1,number2):
if number1 >= number2: return number1 else: return number2
# Call the function by passing function argument max_number(10,4) |
Python Program 4 |
”’ The main purpose of this Program is to take a String Variable and display alphabet at specified index ”’
s = “Obey your Teachers” # Character at index 2 will be displayed on screen i.e., ‘e’ s[2] |
Python Program 5 |
”’ The main purpose of this Program is to take a String Variable and display alphabets at specified index ”’
MESSAGE = “Obey your Teachers”
# The output displayed on screen will be ‘eOT’ Sum = MESSAGE[2] + MESSAGE[0] + MESSAGE[8] |
Python Program 6 |
”’ The main purpose of this Program is to take String Variable and remove left and right spaces of String ”’
message = ” Do Zikar Everyday “; message.lstrip() # Remove left space using lstrip() function message.rstrip() # Remove left space using rstrip() function |
Your Turn Task 1
- Task
- Write Nine Python Programs
- Three should be Very Bad examples of Naming Scheme / Conventions
- Three should be Bad examples of Naming Conventions
- Three should be Good examples of Naming Conventions
- Write Nine Python Programs
Data and Code Organization
- File vs Folder
- File
- A File is the basic storage unit in a Computer
- Folder
- A Folder (a.k.a. Directory) holds one or more Files
- Data and Code Organization
- Definition
- Data and Code Organization refers to the systematic arrangement of Data and Code used in developing a Software
- Purpose
- The main purpose of Data and Code Organization is to
- Improve the overall management of the Data and Code
- The main purpose of Data and Code Organization is to
- Importance
- Data and Code Organization helps companies to ensure Data Security
- i.e., vital Data and Code is never lost and is protected inside the company
- Data and Code Organization helps companies to ensure Data Security
- Applications
- Data and Code Organization helps to
- easily and quickly search Data and Code
- easily and quickly update Data and Code
- protect Data and Code from theft, breaches and losses
- Data and Code Organization helps to
Best Practices of Data and Code Organization
- Best Practices of Data and Code Organization
- Best Practices for Data and Code Organization are as follows
- Best Practice 1
- Put One Project in One Directory / Folder
- Make separate Sub-directories / Sub-folders for
- Data
- Code
- Documentation
- In Data Sub-directory / Sub-folder
- Make Sub-sub-directories / Sub-sub-folders (If Needed)
- In Code Sub-directory / Sub-folder
- Make Sub-sub-directories / Sub-sub-folders (If Needed)
- In Documentation Sub-directory / Sub-folder
- Make Sub-sub-directories / Sub-sub-folders (If Needed)
- Make separate Sub-directories / Sub-folders for
- Note
- You can make Sub-directories / Sub-folders to any level depending upon your requirement
- Put One Project in One Directory / Folder
- Best Practice 1
- Example – Data and Code Organization
- The following Figure shows Data and Code Organization for Titanic Project
- Absolute Path vs Relative Path
- Absolute Path
- An Absolute Path always requires to provide complete Directory / Folder list required to locate a File / Directory / Folder
Absolute Path |
~/Titanic/Data/test_data |
- Relative Path
- A Relative Path allows us to specify the location of a Directory / Folder relative to another Directory / Folder
Relative Path |
../Data/test_data |
- Best Practices of Data and Code Organization
- Best Practice 2
- Use Relative Paths
- Best Practice 2
Relative Path |
../RawData/some_file.csv |
- Version Control System
- Definition
- Version Control Systems is a Software which keeps record of changes made to Code / Data / Documentation File(s) in a Project by keeping a track of modifications made to each and every Code / Data / Documentation File in the Project
- Advantages
- Version Control System allows us to
- compare various versions of Code / Data / Documentation File(s)
- identify differences between various versions of Code / Data / Documentation File(s)
- Identify which version is currently in Development, Quality Assurance, and Production Phases of Software Development Life Cycle
- Version Control System allows us to
- Example
- Best Practices of Data and Code Organization
- Best Practice 3
- Use Version Control System
- Best Practice 3
- Best Practices of Data and Code Organization
- Best Practice 4
- Name of File / Folder should clearly reflect the content of the File / Folder
- File / Folder Naming Scheme / Convention
- Use Consistent Computer Readable Naming Convention
- Avoid spaces in file and dir names
- Use dashes-to-separate-words
- Use Consistent Computer Readable Naming Convention
- Best Practice 4
Version-01-First-Program-in-Python
- Be consistent when Naming Files – Use Lower Case / Upper Case
Correct
version-01-first-program-in-python
Correct
Version-01-First-Program-in-Python
- Use Meaningful (Expressive) File and Directory Names
version-01-first-program-in-python
- Avoid special characters or spaces in a File Name
Correct
version-01-first-program-in-python
Wrong
version-01#first-program-in-python
- Avoid using final in file name
Correct
version-01-first-program-in-python
Wrong
version-01-first-program-in-python(final)
- Don’t Use Proprietary File Formats
- Proprietary Formats are formats that require a specific tool (and a specific license often) to open
- Examples
- Microsoft Excel (.xlsx)
- Microsoft Word (.docx)
- Write ReadMe Files
- Definition – README File
- A README File is a Plain Text File
- A README File is a form of Documentation
- A README File contains information about other Files in a Directory / Folder / Archive of Computer Software
- Definition – README File
- Best Practices of Data and Code Organization
- In the Previous Slides, I identified 04 Best Practices for Data and Code Organization, which are as follows
- Best Practice 1
- Put One Project in One Directory / Folder
- Make separate Sub-directories / Sub-folders for
- Data
- Code
- Documentation
- In Data Sub-directory / Sub-folder
- Make Sub-sub-directories / Sub-sub-folders (If Needed)
- In Code Sub-directory / Sub-folder
- Make Sub-sub-directories / Sub-sub-folders (If Needed)
- In Documentation Sub-directory / Sub-folder
- Make Sub-sub-directories / Sub-sub-folders (If Needed)
- Best Practice 2
- Use Relative Paths
- Best Practice 3
- Use Version Control System
- Best Practice 4
- Name of File / Folder should clearly reflect the content of the File / Folder
- File / Folder Naming Scheme / Conventions
- Use Consistent Computer Readable Naming Conventions
- Avoid spaces in file and dir names
- Use dashes-to-separate-words (slugs)
- Be Consistent When Naming Files – Use Lower Case / Upper Case
- Use Meaningful (Expressive) File and Directory Names
- Avoid special characters or spaces in a file name
- Avoid using final in File Name
- Don’t Use Proprietary File Formats
- Write ReadMe files
- Best Practice 1
- Best Practices for Data and Code Organization Cont…
- Insha Allah, in the next Slides, I will present examples of Good and Bad Data and Code Organization
- Example 1 - Best Practices for Data and Code Organization
- Given
- Ms. Samavi is developing Software (called Calculate Average) which calculates the average of marks obtained by students enrolled in Introduction to Python course. She mainly needs one Data File which contains the marks of students in Introduction to Python course and one Code File (a Jupyter Notebook File).
TODO and Your Turn
TODO Task 1
- Task
- Consider the following scenario and answer the questions given below
- Ms. Samavi is developing Software (called Predict Surah Category) to predict whether a Surah in the Holy Quran is Makki or Madni? She mainly requires two Data Files (train and test) and one Code File (a Jupyter Notebook File).
- Note
- Your answer should be
- Well Justified
- Your answer should be
- Question
- How many main Folders / Directories will be there?
- What are the main components of the Project that need Organization?
- How will you organize the main components of the Project?
- What names will you use for Files, Folders and Sub-Folders?
- Draw a Figure which shows the Organization of the main components of the Project?
Your Turn Task 1
- Task
- Select a scenario (similar to the one given in the TODO) and answer the questions given below
- Note
- Your answer should be
- Well Justified
- Your answer should be
- Question
- How many main Folders / Directories will be there?
- What are the main components of the Project that need Organization?
- How will you organize the main components of the Project?
- What names will you use for Files, Folders and Sub-Folders?
- Draw a Figure which shows the Organization of the main components of the Project?
Code Grouping
- Code Grouping
- Definition
- Code Grouping is defined as the process of grouping Code into blocks
- Purpose
- The main purpose of Code Grouping is to
- Improve the readability and understandability of the Code
- The main purpose of Code Grouping is to
- Best Practices for Code Grouping
- Best Practices for Code Grouping are as follows
- Best Practice 1
- Each Block of Code should be separated with one or more blank lines
- Best Practice 1
- Example 1 - Best Practices for Code Grouping
'''
The main purpose of this Program is to take an Integer Variable and display the value of Variable (called "number") if it is less than 5 on Output Screen
'''
number = 10
if number > 5:
print(number, " is greater than 5 ")
- Example 2 - Best Practices for Code Grouping
'''
The main purpose of this Program is to take an Integer Variable and display the value of Variable (called "count ") up-to 3 on Output Screen using Loop
'''
count = 0
while (count < 3):
count = count + 1
print(count)
- Example 3 - Best Practices for Code Grouping
'''
The main purpose of this Program is to display message “ The best person is the one who benefits human beings” on Output Screen using Function
'''
def display_message():
print("The best person is the one who benefits human beings")
display_message()
- Note
- In above Example 1, Example 2 and Example 3
- Each Block of Code is separated with
- One blank line
- Each Block of Code is separated with
- Best Practices for Code Grouping Cont…
- Insha Allah, in the next Slides, I will present examples of Good and Bad Code Grouping
- Example 1 – Best Practices for Code Grouping
- Given
- Consider a Python Program, which passes two Integer Variables as parameters to a function and checks whether Number1 is greater than Number2?
- Task
- Evaluate the quality of Code Grouping
'''
The main purpose of this program is to take two Integer Variables as input from a User, display which number is greater, on Output Screen
'''
number1 = int(input("Enter first integer number: "))
number2 = int(input("Enter second integer number: "))
if number1 > number2:
print("Number1 is greater than Number2")
else:
print("Number2 is greater than Number1")
- Remarks
- Bad Code Grouping
- Reasons
- There are four Blocks of Codes and they are not separated by one or more blank lines
- Example 2 – Best Practices for Code Grouping
- Given
- Consider a Python Program, which pass two Integer Variables as parameters and check whether Number1 is greater than Number2?
- Task
- Evaluate the quality of Code Grouping
'''
__author__ = Ms. Samavi Salman
__copyright__ = Copyright (C) 2020 Ms. Samavi Salman
__license__ = Public Domain
__version__ = 1.0
'''
'''
The main purpose of this program is to take two Integer Variables as input from a User, display which number is greater, on Output Screen
'''
number1 = int(input("Enter first integer number: "))
number2 = int(input("Enter second integer number: "))
if number1 > number2:
print("Number1 is greater than Number2")
else:
print("Number2 is greater than Number1")
- Remarks
- Good
- Reasons
- Code Grouping is good because Code is written by following the Best Practices for Code Grouping 😊
TODO and Your Turn
TODO Task 1
- Task
- Consider the following six Python Programs and answer the questions given below
- Note
- Your answer should be
- Well justified
- Your answer should be
- Questions
- Write your Remarks about quality of Code Grouping in the Python Programs
- Possible Remarks are
- Very Bad
- Bad
- Good
- Write Reasons of your Remarks
- Possible Remarks are
- Write your Remarks about quality of Code Grouping in the Python Programs
Python Program 1 |
”’ The main purpose of this Program is to take an Integer Variable as input from the User, calculate the square root and display the result on Output Screen ”’
X = int(input(“Enter an integer: “)) Y = X ** 0.5 print(“Square root of number is: “, Y) |
Python Program 2 |
”’ The main purpose of this Program is to print each element of List on Output Screen ”’
listofnumbersfromUser = [10, 12, 14] for number in listofnumbersfromUser: print(number) |
Python Program 3 |
”’ The main purpose of this Program is to takes two Integer Variables and check which number is greater using Function ”’
def max_number(number1,number2):
if number1 >= number2: return number1 else: return number2
# Call the function by passing function argument max_number(10,4) |
Python Program 4 |
”’ The main purpose of this Program is to take a String Variable and display alphabets at specified index ”’
s = “Obey your Teachers” s[2] |
Python Program 5 |
”’ The main purpose of this Program is to take a String Variable and display alphabets at specified index ”’
MESSAGE = “Obey your Teachers” Sum = MESSAGE[2] + MESSAGE[0] + MESSAGE[8] |
Python Program 6 |
”’ The main purpose of this Program is to take String Variable and remove left and right spaces of String ”’
message = ” Do Zikar Everyday “; message.lstrip() # Remove left space using lstrip() function message.rstrip() # Remove left space using rstrip() function |
Your Turn Task 1
- Task
- Write Nine Python Programs
- Three should be Very Bad examples of Code Grouping
- Three should be Bad examples of Code Grouping
- Three should be Good examples of Code Grouping
- Write Nine Python Programs
Exception Handling
- Note
- For details on Exception Handling
- See Chapter 10 – Exception Handling
- Exception vs Exception Handler
- Exception
- In a Programming Language, an Exception is defined as an unplanned event (or Runtime Error), which occurs during the execution of a Program and it disrupts the normal flow of the Program’s instructions
- What Happens When an Exception Occurs?
- When an Exception (unplanned event or error) occurs within a Function / Method, the Function / Method creates an object and hands it off to the Runtime System
- Exception Handler
- An Exception Handler is a piece of Code that stipulates what a Program will do when an Exception occurs in a Program
- Exception Handling
- Definition
- In Programming Languages, Exception Handling is defined as the mechanism of handling Exceptions (or Runtime Errors)
- Purpose
- Only Allah is Perfect 😊
- A Program made a Human cannot be Perfect and it will have
- Scope of Error
- The main purpose of Exception Handling is to
- Handle Runtime Errors which were not perceived by the Programmer(s) at the time of Program development
- Importance
- Exception Handling helps us to
- ensure that the flow of Program instructions does not break when an Exception occurs
- have meaningful Error Reporting
- Identify Error Types (for e.g. File Not Found, IO Exception etc.)
- Exception Handling helps us to
Best Practices for Exception Handling
- Best Practices for Exception Handling
- Below I present Best Practices for Exception Handling
- Best Practice 1
- Use multiple except Statements when the try block contains Python Statements that may throw different types of Exceptions
- Best Practice 1
'''
The main purpose of this Program is take an Integer Variable as input from User and calculate the square root of the Variable using following function in Python: math.sqrt()
'''
# Import math Library
import math
try:
number = int(input("Enter an Integer: "))
square_root = math.sqrt(number)
print(square_root)
except (ValueError) as e:
print("Error: Invalid Input. Square root of Negative numbers cannot be calculated", e)
except (NameError) as e:
print("Error: Invalid Input. Square root of '0' is '0' ", e)
- Best Practices for Exception Handling
- Best Practice 2
- Use a generic except clause, which handles any type of Exception
- i.e., except Exception:
- Note
- Exception can be used with alias name using
- as Keyword
- Exception can be used with alias name using
- Use a generic except clause, which handles any type of Exception
- Best Practice 2
'''
The main purpose of this Program is take an Integer Variable as input from User, calculate the square root of the number using math.sqrt and display the result on Output Screen
'''
# Import math Library
import math
try:
number = int(input("Enter an Integer: "))
square_root = math.sqrt(number)
print(square_root)
except Exception as ex:
print(ex)
'''
The main purpose of this Program is take an Integer Variable as input from User and calculate the modulus of the number and display the result on Output Screen
'''
try:
number = int(input("Enter an Integer: "))
modulus = number % 2 == 0
print(modulus, "is an Even number ")
except Exception as ex:
print(ex)
- Best Practices for Exception Handling
- Best Practice 3
- After except clause(s), you can include an else-Block
- Code in the else-Block executes if Code in the try Block does not raise an Exception
- The else-Block is a good place for Code that does not need the try Block’s protection
- Code in the else-Block executes if Code in the try Block does not raise an Exception
- After except clause(s), you can include an else-Block
- Best Practice 3
'''
The main purpose of this Program is take an Integer Variable as input from User and calculate the modulus of the number and display the result on Output Screen
'''
try:
number = int(input("Enter an Integer: "))
modulus = number % 2 == 0
print(modulus, "is an Even number ")
except:
print("Error: Invalid Input. Modulus of ZERO is ZERO ")
else:
print(modulus, "is an Odd number")
- Best Practices for Exception Handling
- Best Practice 4
- Use finally Block for the piece of Code which should be executed in all situations
- Best Practice 4
'''
The main purpose of this Program is take two Positive Integer Variables as input from User, calculate the sum of the number and display the sum on Output Screen
'''
try:
number1 = int(input("Enter first Positive Integer: "))
number2 = int(input("Enter second Positive Integer: "))
sum = number1 + number2
print(sum)
except:
print("Error: Invalid Input. Input number is a Negative Integer")
finally:
print("The purpose of program is to calculate sum of Positive Integers ")
- Example 1 – Best Practices for Exception Handling
- Given
- Consider a Python Program, which takes two Integer Variables as input from User and calculate the sum / subtraction / product / division of the numbers on User’s choice and display the sum on Output Screen?
- Task
- Your Code should have the ability to properly handle Exception(s) (Runtime Errors(s))
'''
The main purpose of this Program is taken two Integer Variables as input from User and calculate the sum / subtraction / product / division of the numbers on User’s choice and display the sum on Output Screen
'''
try:
choice = int(input("Please enter choice of operation from 1-4: "))
number1 = int(input('Enter your first Integer: '))
number2 = int(input('Enter your second Integer: '))
if choice == 1:
print(number1 + number2)
elif choice == 2:
print(number1 - number2)
elif choice == 3:
print(number1 * number2)
elif choice == 4:
print(number1 / number2)
- Remarks
- Very Bad Exception Handling
- Reasons
- Exception Handling is of very poor quality because the following Best Practices are not followed
- There is no except Block after try
- There is no else Block after try
- There is no finally Block after try
- Arbitrary Exceptions are not handled
- Exception Handling is of very poor quality because the following Best Practices are not followed
- Example 2 – Best Practices for Exception Handling
- Given
- Consider a Python Program, which takes two Integer Variables as input from User and calculate the sum / subtraction / product / division of the numbers on User’s choice and display the sum on Output Screen?
- Task
- Your Code should have the ability to properly handle Exception(s) (Runtime Errors(s))
'''
The main purpose of this Program is take two Integer Variables as input from User and calculate the sum / subtraction / product / division of the numbers on User’s choice and display the sum on Output Screen
'''
try:
choice = int(input("Please enter choice of operation from 1-4: "))
number1 = int(input('Enter your first Integer: '))
number2 = int(input('Enter your second Integer: '))
if choice == 1:
print(number1 + number2)
elif choice == 2:
print(number1 - number2)
elif choice == 3:
print(number1 * number2)
elif choice == 4:
print(number1 / number2)
except ValueError:
print("Error: Invalid Numbers. Please enter valid numbers ")
else:
print("Error: Invalid Choice. Please enter choice from 1-4 ")
finally:
print("Thankyou for using our Calculator. ")
- Remarks
- Good Exception Handling
- Reasons
- Exceptions are of good quality because they are written by following the Best Practices 😊
TODO and Your Turn
TODO Task 1
- Task
- Consider the following four Python Programs and answer the questions given below
- Note
- Your answer should be
- Well justified
- Your answer should be
- Questions
- Write your Remarks about quality of Code Grouping in the Python Programs
- Possible Remarks are
- Very Bad
- Bad
- Good
- Possible Remarks are
- Write Reasons of your Remarks
- Write your Remarks about quality of Code Grouping in the Python Programs
Python Program 1 |
”’ The main purpose of this Program is to take a String Variable and display the Character at specific index on Output Screen ”’ try: word = ‘Solution’ print(word[8]) except: print(“Error: Invalid Index. The message contains Characters upto 7 indexes”) |
Python Program 2 |
”’ The main purpose of this Program is take Positive Integer as input from the User and display the value on Output Screen ”’
try: number = int(input(“Enter a Positive Integer: “)) if(number <= 0): raise ValueError(number, “is a Negative number”) except ValueError: print(“Error: Invalid Input. Please enter Positive Integer”) finally: print(“The program is completely executed “) |
Python Program 3 |
”’ The main purpose of this Program is to takes two Integer Variables and check which number is greater using Function ”’
number1 = 10 number2 = 0 try: print(number1/number2) except ZeroDivisionError: raise Exception(“Error: Invalid Number. The number cannot be divided with Zero “) |
Python Program 4 |
”’ The main purpose of this Program is to print the value of an Integer Variable on Output Screen ”’
try: print(number) except: print(“Error: Variable is not defined. Please declare the variable and then use it. “) except: print(“Sorry! Some other error occurred “) |
Your Turn Task 1
- Task
- Write Five Python Programs
- Three should be Very Bad examples of Exception Handling
- Three should be Bad examples of Exception Handling
- Three should be Good examples of Exception Handling
- Write Five Python Programs
Chapter Summary
- Chapter Summary
In this Chapter, I presented the following main concepts:
- Coding Standards
- Coding Standards are collections of Coding rules, guidelines, and best practices
- Comment
- Comments are text notes added to a Program to provide explanatory information about the Source Code
- Types of Comments
- Single Line Comment
- Multi Line Comment
- Best Practices for Comments
- Some of the Best Practices in Commenting Code are as follows
- Comment your Code
- i.e., when writing your Code, also Comment your Code
- After completing the Coding (with proper Comments), again go through the entire Code (and Comments) and
- Check the quality of Comments
- Comments should be of high quality and self-explanatory
- i.e., anyone can understand your Code without taking any help from you
- Be consistent in the use of Commenting Style
- i.e., Use only one Commenting Style in all the Comments
- Before writing Comments of Code, your Comments should present the
- Copyright Information
- Authorship Information
- Main purpose of the Program
- Comments should be short, simple and easy to understand
- Comments should not mix up with the Code
- i.e., when writing your Code, also Comment your Code
- Comment your Code
- Some of the Best Practices in Commenting Code are as follows
- Software Documentation
- Any written text, illustrations or video that describes a Software to its Users is called Software Documentation (or Program Documentation)
- Guidelines for Creating High Quality Software Documentation
- To produce high quality Software Documentation some of the main guidelines are as follows
- Software Documentation should be
- complete and correct
- Software Documentation should be written from the
- point of view of the reader
- Software Documentation should follow the
- industry standards
- Consistency
- Consistency is defined as steadfast adherence to the same principles of Character over time
- PEP 8 – Official Coding Style Guide for Python
- PEP stands for Python Enhancement Proposal
- The PEP 8 is the Style Guide for Python Code and it mainly covers
- Formatting
- Comments
- Naming Conventions
- Indentation Style
- In Computer Programming, an Indentation Style is a convention governing the indentation of blocks of Code to convey Program Structure
- The PEP 8 is the Style Guide for Python Code and it mainly covers
- PEP stands for Python Enhancement Proposal
- Best Practices for Indentation
- In the Previous Slides, I identified 11 Best Practices for Indentation, which are as follows
- Best Practice 1
- Leave a Blank Line before Starting a Comment
- Best Practice 2
- There should be a Single Space on Left and Right Side of a Variable / Constant / Operator in a Python Statement
- Best Practice 3
- In an if Python Statement, Python Statement(s) after if Condition should be Indented with
- 4 Spaces
- In an if Python Statement, Python Statement(s) after if Condition should be Indented with
- Best Practice 4
- In an if-else Python Statement, Python Statement(s) after if Condition and else Python Statement should be Indented with
- 4 Spaces
- In an if-else Python Statement, Python Statement(s) after if Condition and else Python Statement should be Indented with
- Best Practice 5
- In a loop Python Statement, Python Statement(s) after loop Python Statement, should be Indented with
- 4 Spaces
- In a loop Python Statement, Python Statement(s) after loop Python Statement, should be Indented with
- Best Practice 6
- In a function Python Statement, Python Statement(s) after function Python Statement should be Indented with
- 4 Spaces
- In a function Python Statement, Python Statement(s) after function Python Statement should be Indented with
- Best Practice 7
- If a Python Statement is greater than 79 characters then
- Wrapping long lines inside parentheses, brackets and braces
- If a Python Statement is greater than 79 characters then
- Best Practice 8
- Usage of blank spaces
- After Class Definition use double blank spaces
- After Function / Method Definition use single blank space
- Best Practice 9
- In a Python Program, write one statement per line
- Best Practice 10
- In an import Python Statements, each import Python Statement should be on a separate line
- Best Practice 11
- In a Python Statement, use proper White Spaces in expressions and statements
- Consistency in Naming Scheme
- Set of rules for writing Identifiers and other entities in Source Code and Documentation of a Python Program is called Naming Scheme / Convention
- Consistency in Naming Scheme
- In a Python Statement, use proper White Spaces in expressions and statements
- Best Practice 1
- In the Previous Slides, I identified 11 Best Practices for Indentation, which are as follows
- Best Practices for Naming Convention
- In the Previous Slides, I identified 6 Best Practices for Naming Convention, which are as follows
- Best Practice 1
- Variable Name
- Variable Name should be in lower case
- Avoid using single character (x,y,z,l,i) variable name
- Use snake case for variable names
- User underscore to separate words in long variable names
- Use expressive variable names
- Avoid variable names that begin with a number
- Avoid using Special Characters (@,!,#,$) in variable names
- Best Practice 1
- Best Practice 2
- Constant Name
- Constants are usually declared and assigned values within a module
- The naming convention for constants is an aberration
- Constant names should be all CAPITAL letters
- Best Practice 3
- Function Argument
- If function argument name clashes with keyword use trailing underscore
- Use meaningful names
- The lowercase naming convention should be followed
- Function Argument
- Best Practice 4
- Module Name
- Prefer underscores for long module names
- Best Practice 5
- Package Name
- Avoid underscores for package names
- Best Practice 6
- Argument of Instance Method
- The first Argument of an Instance Method (the basic Class Method with no strings attached) should always be self
- This points to the Calling Object
- Best Practice 7
- Argument of Class Method
- The first argument of a class method should always be cls This points to the class, not the object instance
- Best Practice 8
- Follow CapWord (or camelCase) naming convention. Just start each word with a capital letter and do not include underscores between words
- PEP 8 suggests that you use CamelCase for class definitions
- If a class contains a subclass with the same attribute name, consider adding double underscores to the class attribute
- Best Practice 9
- Exception Classes
- Use the suffix Error for exception classes
- Best Practice 10
- Use of Underscore
- Single Leading Underscore _var
- Naming convention indicating name is meant for internal use. A hint for programmers and not enforced by programmers
- Double Leading and Trailing Underscore __var
- Triggers name mangling when used in class context. Enforced by the Python interpreter
- Underscore _
- Used as a name for temporary variables
- Single Leading Underscore _var
- Use of Underscore
- In the Previous Slides, I identified 6 Best Practices for Naming Convention, which are as follows
- Data and Code Organization
- File
- A File is the basic storage unit in a Computer
- Folder
- A Folder (a.k.a. Directory) holds one or more Files
- File
- Data and Code Organization
- Data and Code Organization refers to the systematic arrangement of Data and Code used in developing a Software
- Best Practices of Data and Code Organization
- In the Previous Slides, I identified 4 Best Practices for Data and Code Organization, which are as follows
- Best Practice 1
- Put One Project in One Directory / Folder
- Make separate Sub-directories / Sub-folders for
- Data
- Code
- Documentation
- In Data Sub-directory / Sub-folder
- Make Sub-sub-directories / Sub-sub-folders (If Needed)
- In Code Sub-directory / Sub-folder
- Make Sub-sub-directories / Sub-sub-folders (If Needed)
- In Documentation Sub-directory / Sub-folder
- Make Sub-sub-directories / Sub-sub-folders (If Needed)
- Best Practice 1
- Best Practice 2
- Use Relative Paths
- Best Practice 3
- Use Version Control System
- Best Practice 4
- Name of File / Folder should clearly reflect the content of the File / Folder
- File / Folder Naming Scheme / Conventions
- Use Consistent Computer Readable Naming Conventions
- Avoid spaces in file and dir names
- Use dashes-to-separate-words (slugs)
- Be Consistent When Naming Files – Use Lower Case/Upper Case
- Use Meaningful (Expressive) File and Directory Names
- Avoid special characters or spaces in a file name
- Avoid using final in file name
- Don’t Use Proprietary File Formats
- Proprietary formats are formats that require a specific tool (and a specific license often) to open. Examples include Excel (.xls) or Word (.doc)
- Write ReadMe files
- A README file contains information about other files in a directory or archive of computer software.
- A form of documentation, it is usually a simple plain text file called READ.ME , README
- In the Previous Slides, I identified 4 Best Practices for Data and Code Organization, which are as follows
- Code Grouping
- Code Grouping is defined as the process of grouping Code into blocks
- Best Practices for Code Grouping
- Below I present Best Practices for Code Grouping
- Best Practice 1
- Each blocks of code should be separated with some spaces between them
- Best Practice 1
- Below I present Best Practices for Code Grouping
- Exception
- An exception is an event, which occurs during the execution of a program that disrupts the normal flow of the program’s instructions
- Exception Handler
- An Exception Handler is a piece of Code that stipulates what a Program will do when an Exception occurs in a Program
- Exception Handling
- In Programming Languages, Exception Handling is defined as the mechanism of handling Exceptions (or Runtime Errors)
- Best Practices for Exception Handling
- Below I present Best Practices for Indentation
- Best Practice 1
- Use multiple except Statements when the try block contains Python Statements that may throw different types of Exceptions
- Best Practice 2
- Use a generic except clause, which handles any type of Exception
- i.e., except Exception:
- Use a generic except clause, which handles any type of Exception
- Note
- Exception can be used with alias name using
- as Keyword
- Exception can be used with alias name using
- Best Practice 3
- After except clause(s), you can include an else-Block
- Code in the else-Block executes if Code in the try Block does not raise an Exception
- The else-Block is a good place for Code that does not need the try Block’s protection
- Best Practice 1
- Best Practice 4
- Use finally Block for the piece of Code which should be executed in all situations
- Below I present Best Practices for Indentation
In Next Chapter
- In Next Chapter
- In Sha Allah, in the next Chapter, I will present a detailed discussion on
- Exception Handling in Python