Python Report PDF
Python Report PDF
Python Report PDF
PYTHON
Submitted by
Shubham Kaushik
11702234
B.tech Hons. (Computer Science)
DECLARATION
I hereby declare that I have completed my six weeks summer training at Telcocrats
from 01 June 2019 to 12 July 2019. I have declare that I have worked with full
dedication during these six weeks of training and my learning outcomes fulfill the
requirements of training for the award of degree of B.tech, Lovely Professional
University, Phagwara.
Shubham Kaushik
11702234
Acknowledgement
It is our proud privilege and duty to acknowledge the kind of help and guidance received
from several people in preparation of this report. It would not have been possible to
prepare this report in this form without their valuable help, cooperation and guidance.
First and foremost, I wish to record my sincere gratitude to the faculties of Lovely
Professional University for giving me this opportunity to learn advanced this
technology and develop new skills.
I would like to give my sincere gratitude to the offline training website “Telcocrats” for
giving me this chance to assimilate this developing and widely used technology. The
summer training on “Python” was very helpful in gaining the necessary knowledge in
this emerging technology . The contribution and technical support of the Telcocrats
team in preparing this report are greatly acknowledged.
Last but not the least, I wish to thank my parents for financing our studies in this
college as well as for constantly encouraging me to learn and grow. Their personal
sacrifice in providing this opportunity to learn this program is gratefully acknowledged.
Page|4
Certificate
Page|5
Table of Contents
Topics Page no.
6. Testing
7. Gantt chart 41
8. Coding
9. Conclusion 46
Page|6
Module – 1
IntroductionTo Python And Its Installation
Introduction
Python is an interpreted high-level programming language for general-purpose
programming. Created by Guido van Rossumand first released in 1991, Python has a
design philosophy that emphasizes code readability, notably using significant
whitespace. It provides constructs that enable clear programming on both small and
large scales.
Python interpreters are available for many operating systems. CPython, the
reference implementation of Python, is open source software and has a community-
based development model, as do nearly all of its variant implementations. CPython
is managed by the non-profit Python Software Foundation.
The language's core philosophy is summarized in the document The Zen of Python
(PEP 20), which includes aphorisms such as:
Rather than having all of its functionality built into its core, Python was designed to
be highly extensible. This compact modularity has made it particularly popular as a
means of adding programmable interfaces to existing applications.
Downloading Python
If we don’t already have a copy of Python installed on our computer, we will need to
open up our Internet browser and go to the Python download page
(http://www.python.org/download/).
Now that we are on the download page, select which of the software builds we
would like to download. For the purposes of this article we will use the most up to
date version available (Python 3.6.3).
Page|8
Once we have clicked on that, we will be taken to a page with a description of all the
new updates and features of 3.4.1, however, we can always read that while the
download is in process. Scroll to the bottom of the page till we find the “Download”
section and click on the link that says “download page.”
Now we will scroll all the way to the bottom of the page and find the “Windows
x86 MSI installer.” If we want to download the 86-64 bit MSI, feel free to do so.
We believe that even if we have a 64-bit operating system installed on our
computer, the 86-bit MSI is preferable. We say this because it will still run well
and sometimes, with the 64-bit architectures, some of the compiled binaries and
Python libraries don’t work well.
Installing Python
Once we have downloaded the Python MSI, simply navigate to the download
location on our computer, double clicking the file and pressing Run when the
dialog box pops up.
If we are the only person who uses our computer, simply leave the “Install for all users”
option selected. If we have multiple accounts on our PC and don’t want to install it
across all accounts select the “Install just for me” option then press “Next.”
Scroll down in the window and find the “Add Python.exe to Path” and click on the
small red “x.” Choose the “Will be installed on local hard drive” option then press
“Next.” Now that we have completed the installation process, click on “Finish.
P a g e |9
Module – 2
Using Variables in Python
Data types and Variables
Data :- Raw facts and figures
Data Type :- Classification of data items
Data
types in
Python
Sequenc
Numeric Boolean e Dictionary
Complex
Integer Float Numbers String List Tuple
Variables :- Variable is the name given to an object, not to the memory location.
Variables are nothing but reserved memory locations to store values. This means that
when we create a variable we reserve some space in memory. Based on the data type
of a variable, the interpreter allocates memory and decides what can be stored in the
reserved memory.
P a g e | 11
Prefix Base
Interpretation
Float :- The float type in Python designates a floating-point number. float values are
specified with a decimal point. Optionally, the character e or E followed by a positive or
negative integer may be appended to specify scientific notation.
Floating point numbers are represented internally as binary (base-2) fractions.
Most decimal fractions cannot be represented exactly as binary fractions.
P a g e | 12
String literals may be delimited using either single or double quotes. All the characters
between the opening delimiter and matching closing delimiter are part of the string.
For example:
I am a string
>>>type(“I am a string”)
<class ‘str’>
We can accomplish this using a backslash (\) character. A backslash character in a string
indicates that one or more characters that follow it should be treated specially.
P a g e | 13
The following is a table of escape sequences which cause Python to suppress the
usual special interpretation of a character in a string:
String Operators
P a g e | 14
String Operators
format() count()
capitalize() find()
isalpha(
upper() )
islower(
lower() )
isupper(
title() )
index() isdigit()
List :- List is an ordered sequence of items. It is one of the most used datatype in
Python and is very flexible. All the items in a list do not need to be of the same
type.Declaring a list is pretty straight forward. Items separated by commas are
enclosed within brackets [ ].
We can use the slicing operator [ ] to extract an item or a range of items from a list.
Index starts from 0 in Python.
P a g e | 15
> a = [1,2,3]
> a[2]=4
> a
[1, 2, 4]
Tuples are used to write-protect data and are usually faster than list as it
cannot change dynamically.
We can use the slicing operator [] to extract items but we cannot change its value.
P a g e | 16
* Repetition in membership
not in
[ ] Slice membership
len( ) :- Calculates the length of the list and tuple
max( ) :- Finds the largest value from the list and tuple
min( ) :- Finds the smallest value from the list and tuple
append( ) pop( )
reverse(
insert( ) )
remove( ) sort( )
P a g e | 17
> s1 = “Internshala”
[ ‘I’ , ’n’ , ’t’ , ’e’ , ’r’ , ’n’ , ’s’ , ’h’ , ’a’ , ’l’ , ’a’ ]
>>> tuple(s1)
( ‘I’ , ’n’ , ’t’ , ’e’ , ’r’ , ’n’ , ’s’ , ’h’ , ’a’ , ’l’ , ’a’ )
In Python, dictionaries are defined within braces {} with each item being a pair in the
form key:value. Key and value can be of any type. Key is immutable. A key should not
be repeated, if repeated the last value will be retained
max( ) : finds maximum value from the
dictionary eg- max(mobiles)
min( ) : finds minimum value from the
dictionary eg- min(mobiles)
del( ) : can be used to delete
objects syntax-del(keyword)
eg- del(OnePlus 5T)
pop( ) : This method can be used to delete
objects eg- mobiles.pop(“Lava Z80”)
clear( ): This method returns empty
object eg- mobiles.clear( )
Module – 3
Operators in Python
Arithmetic Operators
P a g e | 20
Comparison Operators
Logical Operators
P a g e | 21
Using Loops
Programming languages provide various control structures that allow for more
complicated execution paths.
A loop statement allows us to execute a statement or group of statements multiple
times. The following diagram illustrates a loop statement –
Example :
For Loop:
> for mynum in [1, 2, 3, 4,
5]: print "Hello", mynum
Hello
1
Hello
2
Hello
3
Hello
4
Hello
P a g e | 22
5
While Loop:
> count = 0
> while (count < 4):
print 'The count is:',
Using Functions
Example :
1. def printme( str ):
"This prints a passed string into this function"
print str
return
2. # Function definition is here
def printme( str ):
"This prints a passed string into this function"
print str
return;
# Now we can call printme function
printme("I'm first call to user defined
function!") printme("Again second call to the
same function")
P a g e | 24
Math Module :- The math module is a standard module in Python and is always
available. To use mathematical functions under this module, you have to import the
module using import math. It contains functions like :
P a g e | 25
P a g e | 26
Module
attributes
Package :- One or more relevant modules can be put into one package. Itmust contain
a special
file _init_.py, which is a packaging list.
_init_.py serves two purposes :-
i. The python interpreter recognizes a folder as package if it contains this file
ii. It exposes specified resources from its module to be imported
Module – 4
Principles of Object – Oriented Programming
Overview of OOP
Programming languaages are classified into various paradigms like
procedural, imperative and object – oriented.
Programming paradigms are a way to classify programming languages
based on their features.
Python supports multiple paradigms like Imperative, Procedural, Object –
Oriented and Functional.
Problems Related to Procedure Oriented language
Procedure Oriented languages make the program difficult to maintain.
Procedure Oriented languages use a lot of global data items and this results in
increased memory overhead.
Procedural approach gives more importance to process and doesn’t consider
data of same importance.
Movements of data across functions is unrestricted.
Essential features of OOPs
o Data Encapsulation
o Inheritance
o Overriding
o Polymorphism
P a g e | 28
Example:-
Module – 6
PyQT :- PyQt is a GUI widgets toolkit. It is a Python interface for Qt, one of the most
powerful, and popular cross-platform GUI library. PyQt was developed by RiverBank
Computing Ltd. The latest version of PyQt can be downloaded from its official website.
PyQt is a blend of Python programming language and the Qt library. PyQT API is a
collection of more then 400 classes.
P a g e | 31
QObject is at the top of the class hierarchy. It is the base class of all the Qt objects.
Qt Designer
Qt Designer is the Qt tool for designing and building graphical user interfaces (GUIs)
with Qt
Widgets. You can compose and customize your windows or dialogs in a what-you-see-is
-what-
you-get (WYSIWYG) manner, and test them using different styles and resolutions.
Widgets and forms created with Qt Designer integrate seamlessly with programmed
code, using
Qt's signals and slots mechanism, so that you can easily assign behavior to graphical
elements.
All properties set in Qt Designer can be changed dynamically within the code.
Furthermore,
features like widget promotion and custom plugins allow you to use your own
components
with Qt Designer.
Qt Designer helps only in designing GUI file, then it needs to be converted into py file. By
using pyuic 5 utility xml file can be converted into .py file and is installed alongwith
PyQT5 package.
We use pyuic5-x myui.ui-o myui.py command to convert ui file to python file.For the
sake of simplicity, we place myuic.ui file in the same folder where pyuic5.exe file is
placed.
Science
o Bioinformatics
System Administration
o Unix
o Web logic
o Web sphere
Web Application Development
P a g e | 33
Uses of Python
System programming
Graphical User Interface Programming
Internet Scripting
Component Integration
Database Programming
Gaming, Images, XML , Robot and more
Features of Python
The following primary factors cited by Python users seem to be these:
Python is object-oriented
Structure supports such concepts as polymorphism, operation
overloading, and multiple inheritance.
Indentation
Indentation is one of the greatest future in Python.
It's free (open source)
Downloading and installing Python is free and easy
Source code is easily accessible
P a g e | 34
Testing
WHITE BOX TESTING (also known as Clear Box Testing, Open Box Testing, Glass Box Testing,
Transparent Box Testing, Code-Based Testing or Structural Testing) is a software testing method in
which the internal structure/design/implementation of the item being tested is known to the tester.
The tester chooses inputs to exercise paths through the code and determines the appropriate
outputs. Programming know-how and the implementation knowledge is essential. White box testing
is testing beyond the user interface and into the nitty-gritty of a system.
This method is named so because the software program, in the eyes of the tester, is like a
white/transparent box; inside which one clearly sees.
BLACK BOX TESTING, also known as Behavioral Testing, is a software testing method in which
the internal structure/design/implementation of the item being tested is not known to the tester.
These tests can be functional or non-functional, though usually functional.
This method is named so because the software program, in the eyes of the tester, is like a black
box; inside which one cannot see. This method attempts to find errors in the following categories:
Gantt chart
Gantt charts are useful tools for planning and scheduling projects. Product managers use
Gantt charts in many different ways. For example, you can create a Gantt chart to manage
your strategic planning process, product release, or user research project.
P a g e | 35
Project legacy
Using Variable in Python
Basic Programming in Python and Principle of OOPS
Developing GUI Using PyQt
Application Of Python in Various Discipline like Data
Science,Advance Photo Processing and Machine Learning
CODING
from tkinter import *
import tkinter.messagebox as tm
grades_of_all_courses = list()
credits_of_all_courses = list()
CGPA = 0
#f = tkFont.Font(family='comic sans MS',size=16)
#def Continue():
#f = tkFont.Font(family='comic sans MS', size=16)
window_1 = Tk()
lbf1 = Label(window_1,bg='sky blue',fg='white',font=('comic sans
MS',14),text='WELCOME TO THE CGPA CALCULATOR.\n'
'PLEASE DO NOT LEAVE ALL THE FIELDS
EMPTY.'
'IF YOU DO NOT HAVE 10 COURSES LEAVE
THE REMAINING ENTRIES AND CLICK ON SUBMIT.\n'
'FIRST SUMBIT THE VALUES AND THEN
CLICK ON CALCULATE CGPA.\n'
'YOUR CGPA WILL BE SHOWN IN A NEW
WINDOW')
lbf1.pack(side='top')
window_1.state('zoomed')
window_1.configure(background='sky blue')
window_1.title('C.G.P.A. CALCULATOR')
label_1 = Label(window_1, bg='sky blue', fg='white', text='Enter the
grade in course '+str(1)).place(x=200,y=120)
course_1 = StringVar()
entry_1 = Entry(window_1, textvariable=course_1).place(x=400,y=120)
labelc_1 = Label(window_1,bg='sky blue', fg='white', text='Enter the
credit hours in course '+str(1)).place(x=200,y=150)
P a g e | 36
ch_1 = StringVar()
entryc_1 = Entry(window_1, textvariable=ch_1).place(x=400,y=150)
course_2 = StringVar()
entry_2 = Entry(window_1, textvariable=course_2).place(x=400,y=180)
labelc_2 = Label(window_1,bg='sky blue', fg='white', text='Enter the
credit hours in course '+str(2)).place(x=200,y=210)
ch_2 = StringVar()
entryc_2 = Entry(window_1, textvariable=ch_2).place(x=400,y=210)
ch_10 = StringVar()
entryc_10 = Entry(window_1, textvariable=ch_10).place(x=400,y=690)
def onclick():
x1 = course_1.get()
xc1 = ch_1.get()
credits_of_all_courses.append(xc1)
grades_of_all_courses.append(x1)
x2 = course_2.get()
xc2 = ch_2.get()
credits_of_all_courses.append(xc2)
grades_of_all_courses.append(x2)
x3 = course_3.get()
xc3 = ch_3.get()
credits_of_all_courses.append(xc3)
grades_of_all_courses.append(x3)
x4 = course_4.get()
xc4 = ch_4.get()
credits_of_all_courses.append(xc4)
grades_of_all_courses.append(x4)
x5 = course_5.get()
xc5 = ch_5.get()
credits_of_all_courses.append(xc5)
P a g e | 39
x6 = course_6.get()
xc6 = ch_6.get()
credits_of_all_courses.append(xc6)
grades_of_all_courses.append(x6)
x7 = course_7.get()
xc7 = ch_7.get()
credits_of_all_courses.append(xc7)
grades_of_all_courses.append(x7)
x8 = course_8.get()
xc8 = ch_8.get()
credits_of_all_courses.append(xc8)
grades_of_all_courses.append(x8)
x9 = course_9.get()
xc9 = ch_9.get()
credits_of_all_courses.append(xc9)
grades_of_all_courses.append(x9)
x10 = course_10.get()
xc10 = ch_10.get()
credits_of_all_courses.append(xc10)
grades_of_all_courses.append(x10)
#print(grades_of_all_courses)
#print(credits_of_all_courses)
n1 = len(grades_of_all_courses)
cc1 = 0
i=0
while i < n1:
if cc1 > 0:
i=i-1
n1 = n1 - 1
if grades_of_all_courses[i] == '':
grades_of_all_courses.pop(i)
cc1 += 1
i += 1
n2 = len(credits_of_all_courses)
cc2 = 0
i=0
while i < n2:
if cc2 > 0:
i=i-1
P a g e | 40
n2 = n2 - 1
if credits_of_all_courses[i] == '':
credits_of_all_courses.pop(i)
cc2 += 1
i += 1
for i in range(len(credits_of_all_courses)):
credits_of_all_courses[i] = int(credits_of_all_courses[i])
button_1 = Button(window_1,bg='sky blue', fg='white',font=('comic sans
MS',16), text='submit',command=onclick).place(x=640,y=330)
def calculate():
grades_scale = {'O': 10, 'A+': 9, 'A': 8, 'B+': 7, 'B': 6, 'C+': 5, 'C': 4}
sum_of_grades = 0
for i in range(len(grades_of_all_courses)):
if grades_of_all_courses[i] in grades_scale:
grades_of_all_courses[i] =
grades_scale[grades_of_all_courses[i]]
for i in range(len(grades_of_all_courses)):
sum_of_grades +=
grades_of_all_courses[i]*credits_of_all_courses[i]
total_credit_hours = 0
for i in range(len(credits_of_all_courses)):
total_credit_hours += credits_of_all_courses[i]
CGPA = sum_of_grades/total_credit_hours
window_2 = Tk()
window_2.state('zoomed')
window_2.configure(bg='yellow')
l = Label(window_2, bg='yellow', fg='black', font=('comic sans MS', 36),
text='YOUR C.G.P.A IS ' + str(CGPA)).place(x=500,y=350)
window_2.mainloop()
Conclusion
I believe the trial has shown conclusively that it is both possible and desirable to use
Python as the principal teaching language:
It is Free (as in both cost and source code).
It is trivial to install on a Windows PC allowing students to take their interest
further. For many the hurdle of installing a Pascal or C compiler on a Windows
machine is either too expensive or too complicated;
It is a flexible tool that allows both the teaching of traditional procedural
programming and modern OOP; It can be used to teach a large number of
transferable skills;
Bibliography
www.telcocrats.com