Professional Documents
Culture Documents
Documentation Mitra 2021
Documentation Mitra 2021
O),
Dist: Kandhamal-762012
A PROJECT DOCUMENTATION ON
Submitted For
PRACTICAL EXAMINATION AISSCE 2021
Submitted By:
MITRABHANU PRADHAN
ROLL No. : 29
CONTENTS
1. Certificate
2. Acknowledgment
10. Testing & Output (Screen Snapshots of all the Output Screens)
11. Conclusion
12. Maintenance
14. Bibliography
Page |3
CERTIFICATE
guidance in a period of 18 days from 26th June 2020 to 08th Jan, 2021
2021.
ACKNOWLEDGEMENT
Finally, I would like to thank all the other members for helping
project report.
. Finally, I would like to thank all the other Stock Entry System
Python Fundamentals
Developed by: Guido Van Rossum in early 1990
Python Indentations
➢ In other programming languages the indentation in code is for readability only, in Python the
indentation is very important. Python uses indentation to indicate a block of code.
➢ Example: Python will give you an syntax error if you skip the indentation:
if 5 > 2:
print("Five is greater than two!")
Tokens:
➢ Keywords
➢ Identifiers (names)
➢ Literals
➢ Operators
➢ Punctuators
Keywords:
➢ These words are having special meaning for the compiler.
➢ Used for special purpose, can’t be taken as normal identifier names
Example: if, elif, else, while, for, class, from, True, False, and, or, not, with, as, in, finally, is,
return, None, continue, break, lambda, try, def, nonical, global, yield, import, assert, pass, except,
raise. In python version, 3.6 there are 37 keywards.
Python Variables
• Used for Creating Variables. Unlike other programming languages,
• Python has no command for declaring a variable. A variable is created at the moment
you first assign a value to it.
Example:
x=5
y = "John"
z=float() #initialize with default float variable
r=str() ; p=int(); q=bool()
s=None; t=True
print(x); print(y); print(z);print(r)
• Variables do not need to be declared with any particular type and can even change
type after they have been set.
Example:
x=4 # x is of type int
x = "Sally" # x is now of type str
print(x)
Literals / Values:
Data items that have fixed / constant values. Python allows several kind of literals:
String Literals:
A string literal is a sequence of characters surrounded by quotes (single or double or triple
quotes).
>>> s1='ram' - valid
>>> s2=''ram'' (two single quote) -SyntaxError: invalid syntax
>>> s2="ram" (double quote) – valid
>>> s2=””ram”” (two double quote) - SyntaxError: invalid syntax
>>> s4=""ram"" (three single quote) Valid
>>> s4="""ram""" (three double quote) valid
String Literal:
➢ Single Line String: line of text enclosed in quotes. >>>str=” I am in the class room ”
➢ Multi Line String : each line last character must be a ‘\’ (backslash).
Example: >>> text=” I am in \
The class \
room “
Escape sequence: These are single characters / non graphic characters followed by \
(backslash). These can be included in a string.
Example:
Example: \\ → for single backslash (\) \’ → for a single quote (‘)
\” → for a double quote(“) \a → for audible bell \b → Back space
\f → Form feed \n→New line character \r → Carriage return \t → Horizontal Tab
\N{name}→ character named name in the Unicode database (Unicode only)
Page |7
Boolean Literals
A Boolean literal value can be True or False.
Example: >>> d=True; r=False
Operators:
Operators are used to perform operations on variables and values.
Python divides the operators in the following groups:
• Arithmetic operators : [ +,-,*,/,//,%,**]
Example: a=7, b=2,
c=a/b; c will be 3.5
d=a//b d will be 3 as integer part of quotient
e=a%b e will be 1 as reminder
• Assignment operators : [ =, +=, -=,*=,/=,//=,%=,**=]
example: >>>a=b; a+=b;
➢ Membership operators: (in, not in) Membership operators are used to test if a sequence is
presented in an object
In: Returns True if a sequence with the specified value is present in the object
not in: Returns True if a sequence with the specified value is not present in the object
Example:
>>> str1=" Raja Ram" >>> str2="Raja" >>> str3="hari"
>>> str1 in str2 - False
>>> str2 in str1 -True
>>> str3 in str1 - False
>>> str3 not in str1 - True
➢ Bitwise operators: <<, >>
<< [ Zero fill left shift ] Shift left by pushing zeros in from the right and let the leftmost bits fall
off
>> [Signed right shift ] Shift right by pushing copies of the leftmost bit in from the left, and let
the rightmost bits fall off
Example:
>>> D=14 >>> D>>2 result in decimal is 3 >>> D>>1 result in decimal is 7
>>> A=16 >>> A>>2 result in decimal is 4
>>> A=3 >>> A>>2 result in decimal is 0
Punctuators: special symbols used to organize statements, expressions and program structure of
python.
Example: ‘ (single quote), ” (Double Quote) , @, #, \, [ ], { }, : etc.
Variable Assignment
Note: in case integers the values from -5 to 0 and 0 to 256 are having fixed memory location with the
loading of the compiler.
>>> n=257; m=257; id(n); id(m) # both id will be different suppose as 35736528 35737088
>>> n=m; id(n); id(m) # both id will be same 35737088 35737088
Or >>> n, m=257; id(n); id(m) # both id will be same 35737088 35737088
Or >>> n, m=257,257; id(n); id(m) # both id will be same 35737088 35737088
We can assign in the following ways:
>>> a=b=c=9 # assigning multiple variable by a single value.
>>>a,b,c=9,2,3 # assigning multiple values to multiple variables
print()- used to send the output to the standard output device normally to monitor.
syntax : print(object[s], [sep=' ' or <separator string>] [end='\n' or <end-string>])
* object[s] may be expression or object separated by comma.
Example: >>>print() - print a blank line only.
>>> print("My ", "School ", "is" , "KVKDML", sep="$")
Output: My $School $is$KVKDML
>>> print("My ", "School ", "is" , "KVKDML", end="$")
Output: My School is KVKDML$
DATA TYPES:
Data type for Numbers:
➢ Integers Numbers
-integers(signed) example: p=int()
-Boolean: False, True are values equivalent to 0 and 1 , example: q=bool()
➢ Floating-point Numbers: 15 digit double precision number , example: r=float()
➢ Complex numbers: example: a+bj here a is real part and bj is imaginary part, example:
a=complex()
String type:
- It may consist of any type of characters as: letters, numbers and special characters.
- Enclosed in single quote or double quote
- Example of valid strings: “123”, ‘123’, “B45TDGG333”, “1.2233OU&%$#UT”
- It can be accessed by index value. Example: >>>s=”SASWAT” >>>s[0] ; s[1]; s[3]
output will be: S A W
- String is immutable.
LIST TYPE
- Sequence data type (collection of list of values).
- Mutable (modifiable) i.e. elements can be changed.
- It can contain mixed values.
- The values in it are to be separated by comma (,) and enclosed in square bracket ([..])
Example: Ls = [10,20,30,40,50,60,70,”KVS”,90]
Index -9 -8 -7 -6 -5 -4 -3 -2 -1
Values 0 1 2 3 4 5 6 7 8
10 20 None 40 50 60 70 KVS 90
P a g e | 10
Example of List:
[ ] – empty list
[1, 2, 3, 4, 5] – list of integers.
[1, 2, 3.5, 2.5, 3.76, 8] – list of numbers (integers and floating)
[‘a’,’b’,’c’] – list of characters
[“One”,”Two”,“Three”] – list of strings
[10, “Raja Ram”, 98, 78500.69] – list of mixed values types
Creating List:
Syntax: ListName = [value1, value2, . . . . , valueN]
>>>sd=[ ] – Blank list / empty list
>>>sd = list( ) – empty list
>>>sd1=[‘abc’,’cst’,’gst’] – string list
>>> sd=list() >>> type(sd) → <class 'list'>
Long List: If a list contains many elements, then to enter such long lists, you can split it
across several lines, like below:
sqrs = [ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400,
484, 529, 576, 625 ]
Nested List: A list can have an element in it, which itself is a list.
Example: >>> sd=[1,2,[8,9],6,5] >>> sd → [1, 2, [8, 9], 6, 5] >>> sd[0] → 1
>>> sd[2] → [8, 9] >>> sd[2][0] → 8 >>> sd[2][1] → 9
>>> sd[3] →6 >>> p=[6,8,9] >>> sd=[1,2,p,6,5]
>>> sd → [1, 2, [6, 8, 9], 6, 5]
What is the difference & Similarities between string and list?
- List is mutable but String is immutable
- List is enclose with [ ] (square brackets) but String is enclosed with ‘ (single quote), “
(doublequote), 3 double quote or 3 single quote.
- Similarity is both are sequences.
P a g e | 11
LIST OPERATIONS
Accessing a List
>>> LS = [10, "HARI PRSAD", 98, 99, 78, 80, 90] >>> len(LS) → 7 # Length of the list
>>> LS[0] → 10 >>> LS[1] → 'HARI PRSAD' >>> LS[1][0] → 'H' >>> LS[1][9] → 'D'
Note: List are like string sequence with forward (0 to len-1) and backward (-1, -len) indexing
and also access like that.
COMPARING LIST:
List can be compared by comparison operators (relational operators) : >, <, ==, >=, <=,!=
Note: it compare each corresponding elements one by one where mismatch occurs then there
only decide the comparison result as true or false.
>>> ls1=[1,2,3,5] >>> ls2=[1,2,2,9] >>> ls1>ls2 → True >>> ls1!=ls2 → True
>>> ls1==ls2 → False >>> ls1<ls2 → False >>> ls1>=ls2 → True
IMPORTANT: HOTS
Storage of List in Memory and assignment or coping in python
>>> c=[1,2,9]
>>> d=c # in this case the same list in c will be share by d as an alias name (alternative name)
>>> c[0]=88 >>> c → [88, 2, 9] >>> d → [88, 2, 9] >>> d=[5,7] >>> c → [88, 2, 9]
>>>d → [5,7]
WAP to find how many times a value exist in a list by showing its index.
LS=[10,20,40,60,10,40]
c=len(LS)
for k in range(0, c):
if(LS[k]==10):
print(k, end=" , ")
append() – used to add an item / single element to the end of the list. It will not return any
value.
Syntax: ListName.append(<itemToAdd>)
Example:
>>> ls=[1,4,7] >>> ls.append(9) >>> ls → [ 1, 4, 7, 9 ]
>>> ls.append([5,6]) # it will append [5,6] as a separate element in the same list.
>>> ls → [ 1, 4, 7, 9, [5,6] ] # now it has been a nested list
>>> ls.append(5,6) # INVALID it will take only one argument (may be a sequence/literal)
>>> ls.append([5,6]) # it is valid because it is one argument and a list only.
P a g e | 13
extend() – used to add multiple elements by extending the length of the list.
Syntax: ListName.extend(<ListToExtend>)
Example:
>>> ls = [1, 4, 7] >>> ls.extend([8,7]) >>> ls → [1, 4, 7, 8, 7]
>>> ls.extend (5,6) # INVALID it will take only one argument as a list only.
>>> ls.extend([5,6]) # it is valid because it is one argument and i.e. a list only.
pop() – used to remove and return the value at a particular index position in the list.
Syntax 1: ListName.pop(<index>)
Syntax 2: ListName.pop() – delete and return the last index value i.e. fromTop
Example:
>>> ls1=[10,20,30,40] >>> ls1.pop() → 30 >>> ls1 → [10, 20, 40]
>>> ls1.insert(2,30) >>> ls1 → [10, 20, 30, 40] >>> v=ls1.pop(2)
>>> v → 30 >>> ls1 → [10, 20, 40]
remove() – used to remove the first occurrence of a given item from the list but does not return
anything.
Syntax: ListName.remove(<item/value>)
>>> ls1=[10,20,10,30,10]
>>> ls1.remove(10)
>>> ls1 → [20, 10, 30, 10]
>>> ls1.remove(10)
>>> ls1 → [20, 30, 10]
>>> ls1.remove(0) # ValueError: list.remove(x): x not in list
clear() – used to remove all the items from the list and the list become empty. And does not
return anything.
Syntax: ListName.clear()
Example: >>> ls1=[10,20,10,30] >>> ls1.clear() >>> ls1 → [ ]
count()- used to return the count of the item that passed as argument. If item is not there then
return zero.
Syntax: ListName.count(<item/value>)
P a g e | 14
reverse() – used to reverse and replace with reverse values in the same list through which the
function is called. And does not return anything.
Syntax: ListName.revserse()
Example: >>>ls1=[10,"ram", 90,80] >>> ls1.reverse() >>> ls1 → [80, 90, 'ram', 10]
sort() – used to sort and replace the list with sorted values. Does not return anything.
Syntax -1 : ListName.sort() - sort in ascending order
Syntax -2 : ListName.sort(reverse=True) - sort in descending order
>>> ls1=[6,5,6,8,-9] >>> ls1.sort() # or >>> ls1.sort(reverse=False)
>>> ls1 → [-9, 5, 6, 6, 8] >>> ls1.sort(reverse=True) >>> ls1 → [8, 6, 6, 5, -9]
Example: () – Empty tuple # Remember: (6) – it is an int only a single value is considered as the
type as it is inside it. # (1,2,3) - tuple with integers # (‘a’,’b’,’c’) - tuple of characters i.e. strings
(“ram”,”hari”,”Jagannath”) - Tuple of strings (10, 2.5,”hari”, ”Jagannath”) - Tuple of mixed values
Accessing Tuple:
>>> t=(5,7,9,"ram",9.9) >>> type(t) → <class 'tuple'> >>> t[0] → 5 >>> t[3] → 'ram'
>>> t[3][1] → 'a' >>> len(t) →5
>>> t[1]=15 → ERROR: TypeError: 'tuple' object does not support item assignment
>>>t[-1] → 9.9 >>> t[-4] → 7
Creating Tuples
Syntax 1: Variable = (value1, value2, value3…, valueN)
Syntax 2: Variable = Tuple() # constructor method
Syntax 3: Variable = Tuple(<sequence>)
>>>T1=() >>>T2=(10,2.5,“ram”,”hari”,”Jagannath”)
>>>T3=tuple(1,2,(5,8),[6,7]) # Invalid the argument need a () >>>T4=tuple((1,2,(5,8),[6,7]))
>>>T5=tuple() # Empty tuple >>> t3=tuple("Jagannath") >>> t3 → ('J', 'a', 'g', 'a', 'n', 'n', 'a', 't', 'h')
>>> t3=tuple(('jagannath','')) >>> t3 → ('jagannath', '')
P a g e | 15
Output
Enter Elements to the Tuple 1: 1,2,"ram
Tuple 1 Elements are: ('1', ',', '2', ',', '"', 'r', 'a', 'm')
Enter Elements to the Tuple 2: 1,2,"ram"
Tuple 2 Elements are: (1, 2, 'ram')
Comparing Tuples:
Two tuples can be compared using >, <, >=, <=, !=, == relational operator. Two tuples can be equal if
they have same number of elements and matching values (if int and float with matching values are
considered as equal). If the values are not matched i.e. bigger and smaller they will be treated as
unequal.
>>> tp1=(1,2,3) >>> tp2=(1,2,3.0) >>> tp1==tp2 → True >>> tp3=(1,2,3)
>>> tp1==tp3 → True >>> tp4=(1,5,1) >>> tp1==tp4 → False >>> tp1>tp2 → False
>>> tp1 → (1, 2, 3) >>> tp2 → (1, 2, 3.0) >>> tp4 → (1, 5, 1) >>> tp2<tp4 → True
>>>tp6=(1,2,0) >>>tp7=(1,2) >>tp6==tp7 → false >>>tp8=(1,2,None)
>>tp6==tp8 → false
P a g e | 16
Unpacking Tuple:
Creating a tuple from a set of values is called packing and its reverse i.e. crating individual values
from a tuple’s elements called unpacking.
Syntax: <var1>,<var2>,<var3>,….=Tuple_name
Example:
>>>tp=(1,20,35) # you can say it as packing.
>>> a,b,c=tp # unpacking i.e. individual values will be assigned to separate variables.
>>> a → 1 >>> b → 20 >>> c → 35 >>> a,b=tp # unpacking Error as Value Error
max() - This method returns the element from the tuple having maximum value. But it does not
support string values in tuple.
Syntax: max(seq) >>> t3 =(1, 4, 3) >>> max(t3) -> 4
Note: but direct compare strings
>>> max("ram") → 'r' >>> max("ram", "hari") → 'ram' >>> max("ram", "hari", "xmas") → 'xmas'
min() - This method returns the element from the tuple having minimum value. But it does not
support string values in tuple. But allows only string by comparing asci values.
Syntax: min(sequence) example: >>> t3 =(1, 4, 3) >>> min(t3) ->1
index() - This method returns the index value of an existing element from the tuple.
Syntax: <sequence>.index(value) example: >>> t3 =(1, 4, 3) >>> t3.index(4) ->1
count() - This method returns the count of a member element /object in a given sequence.
Syntax: <sequence>.count(value) example: >>> t3 =(1, 4, 3, 4, 6, 44) >>> t3.index(4) ->2
tuple() – This method is actually constructor method that can be used to crate tuples form different
type sof values.
Syntax: tuple(sequence) example: >>> t=tuple() # empty tuple
>>>t=tuple(“kvkdml”) # string to tuple ('k', 'v', 'k', 'd', 'm', 'l')
DICTIONARIES
- Mutable data type
- Not a Sequence (unlike a string, list and tuple it is not as sequence as it is a unordered
collection of data)
- Unordered collection of elements in the form of a Key: Value Pair
- Enclosed in { }
- Internally indexed on the basis of keys
- It is just like an English dictionary word, where keys are words and values are equivalent to
meaning of words.
- Dictionaries are also called as associated arrays or mappings or hashes.
- Keys of a dictionary must be immutable: i.e. it should be a number, string, tuple but list
is not allowed, as it is mutable.
Accessing a Dictionary:
Syntax: <dictionary_name>[<key>]
>>> teachers = {(1,2):"ram", (3,4):"Hari"} >>> teachers[(1,2)] → 'ram'
>>> teachers['ram'] → Invalid
P a g e | 17
Traversing a Dictionary
teacher={"R.R.Thakur" : "English" , "B. Sharma" : "Maths", "B.Sasikala": "Biology"}
for key in teacher:
print(key," teaches ", teacher[key] )
-- OUTPUT--
R.R.Thakur teaches English
B. Sharma teaches Maths
B.Sasikala teaches Biology
Example:
>>> teacher={"R.R.Thakur" : "English" , "B. Sharma" : "Maths", "B.Sasikala": "Biology"}
>>> teacher.values() → dict_values(['English', 'Maths', 'Biology'])
>>> k=teacher.values() → values will be store in k as dict_values type but can not be utilized
>>> k=list(teacher.values()) → converting the output to list type
>>> k → ['English', 'Maths', 'Biology']
>>> teacher.keys() → dict_keys(['R.R.Thakur', 'B. Sharma', 'B.Sasikala'])
>>> tp=tuple(teacher.keys()) # to store in a list
>>> tp → ('R.R.Thakur', 'B. Sharma', 'B.Sasikala')
>>>tp[0] →'R.R.Thakur'
>>> s=str(teacher.values()) → converting to string we can’t access or utilize
# Values will be store in s as “dict_values(['English', 'Maths', 'Biology'])”
Characteristics of a dictionary:
- Unordered set of key:values pair.
- Not a sequence (because unordered set of elements)
- Indexed by keys not by numbers
>>> teacher={"R.R.T" : "Eng" , "B.S" : "Maths", "B.S.K": "Bio"}
>>> teacher[0] # INVALID access as KEY ERROR
>>> teacher["B.S"] → 'Maths' # valid as access thorough key
- Key must be unique (duplicate may be allowed but not valuable)
- Mutable (modify using key to values only)
Syntax: <DictionaryName>[key]=<value>
>>> td={10: "Eng" , 20 : "Maths", 30: "Bio"}
>>> td[10] → 'Eng' # same as >>> print(td[10])
>>> td[10] = "CS" # modify 10 key’s value as CS
>>>td → {10: 'CS', 20: 'Maths', 30: 'Bio'}
Example:
>>> td={50: "Eng" , 10 : "Maths", 20: "Bio"}
P a g e | 18
Keys Values
50 Bio
10 Eng
20 Maths
Adding elements to dictionary:
Syntax: <dictionaryName>[key]=<value>
>>> td={50: "Eng" , 10 : "Maths", 20: "Bio"}
>>> d → {50: 'Eng', 10: 'Maths', 20: 'Bio'}
>>> d[30]="CS" >>> d -> {50: 'Eng', 10: 'Maths', 20: 'Bio', 30: 'CS'}
Updating element of dictionary:
Syntax: <dictionaryName>[key]=<value>
>>> d[50]="IP" >>> d -> {50: 'IP', 10: 'Maths', 20: 'Bio', 30: 'CS'}
Dictionary function
len() – used to return length of the dictionary i.e. no. of (key:value) pairs.
Syntax: len(<dictionaryName>)
>>> td={50: "Eng" , 10 : "Maths", 20: "Bio"} >>> len(td) → 3
clear() – used to remove all the items from the dictionary and make it empty.
Syntax: <dictionaryName>.clear()
>>> td={50: "Eng" , 10 : "Maths", 20: "Bio"} >>> td.clear() >>> td → {} # now it is empty
get() – used to get /return the item with the given key. It is similar to dictinaryName[key]. Syntax:
dictionaryName.get(<key>)
>>> td={50: "Eng" , 10 : "Maths", 20: "Bio"} >>> td.get(10) → 'Maths' >>> td[10] →'Maths'
values() -used to return all the values in one go from the dictionary.
Syntax: <dictionary>.values()
>>> teacher={"R.R.Thakur" : "English" , "B. Sharma" : "Maths", "B.Sasikala": "Biology"}
P a g e | 19
update()- used to update a dictionary with other dictionary values i.e. add all different (keys with values)
element from other dictionary and if duplicate key:values are there then override. If there same key in
other with different value then value will be updated.
syntax: <dictionaryName>.update(otherDictionary)
>>> emp1={10:"Saswat",20:"Tushar",30:"Sanjeet"}
>>> emp2={20:"Ayush",30:"Sanjeet",40:"Tushar",50:"Digbijay"}
>>> emp1.update(emp2)
>>> emp1 → {10: 'Saswat', 20: 'Ayush', 30: 'Sanjeet', 40: 'Tushar', 50: 'Digbijay'}
>>> emp2 →{20: 'Ayush', 30: 'Sanjeet', 40: 'Tushar', 50: 'Digbijay'}
Comments
Single Line comments
Python has commenting capability for the purpose of in-code documentation.
Comments start with a #, and Python will render the rest of the line as a comment:
Example:
# This is a comment.
Example:
# add two number
a=10 # a value is 10
b=20; """ b value is 10""" - here semicolon is needed to separate
c=a+b; ''' adding number '''
What is the difference between mutable and immutable explain with example:
A mutable object can be changed after it is created, and an immutable object can't. Objects of built-in
types like (int, float, bool, str, tuple, unicode) are immutable. Objects of built-in types like (list, set, dict)
are mutable. Custom classes are generally mutable
Example:
>>> ls=[10,20,"ram"]; tp=(10, 20, "ram")
>>> id(ls); id(tp) output address: 37974784 38187096
>>> ls[0]=99; print(ls); output: [99, 20, 'ram']
>>> id(ls) 37974784
>>> tp[0]=99 # invalid tuple is not mutable (you can not modify the same.)
P a g e | 20
HOTS
>>> tp=(99, 20, 'ram'); print(tp); output will be as: (99, 20, 'ram')
>>> id(tp); output address: 38185360 # here ID changed that means in above case you are
not
# modifying the tuple rather assigning a new value to the tuple, because ID/address has been
changed.
OPERATOR
- For numbers, the + character works as a mathematical operator:
Example: >>> x = 5 >>>y = 10 >>>print(x + y) → Output: 15
- If you try to combine a string and a number, Python will give you an error:
Example: >>>x = 5 >>>y = "John" >>> print(x + y)
Output : Error
Traceback (most recent call last): File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'
HOTS:
** converting asci value to characters and vice versa
>>> chr(65) -> 'A' **used to return characters against ASCII values.
>>> ord('A') -> 65 **used to return ASCII values against characters.
** Sequence data Types in python: str, unicode (string) , list, tuple, buffer, range
** Buffer structures (or simply “buffers”) are useful as a way to expose the binary data from
another object to the Python programmer. They can also be used as a zero-copy slicing
mechanism
Example 1: >>> s = 'Hello world' >>> t = buffer(s, 6, 5)
>>> t -> <read-only buffer for 0x10064a4b0, size 5, offset 6 at 0x100634ab0>
>>> print t -> world
In above code the buffer in this case is a sub-string, starting at position 6 with length 5, and it
doesn't take extra storage space - it references a slice of the string. This isn't very useful for
short strings like this above, but it can be necessary when using large amounts of data. This
example uses a mutable bytearray as follows:
P a g e | 21
** range – The range() is a built-in function of Python which returns a range object, which is
nothing but a sequence of integers. i.e., Python range() generates the integer numbers between
the given start integer to the stop integer, which is generally used to iterate over with for loop.
HOTS:
** python do not have any data type like char
** Unlike C++ in python data types are not keywords example (int, float, str, tuple, list, bool )
** If you are taking variables in the name of data types in python then you can not call the
constructor function of that data type to create a new empty variable.
** It will always better do not take variable with name of data types in python.
Example:
>>> p=int() >>> s=str() >>> int=10 >>> q=int() #INVALID AND ERROR
Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> q=int() TypeError:
'int' object is not callable
>>> str1=str() >>> str="ram" >>> str2=str() #INVALID AND ERROR
Traceback (most recent call last): File "<pyshell#6>", line 1, in <module> str2=str()
TypeError: 'str' object is not callable
SORTING
INSERTION SORTING: insert element at proper place by searching and comparing in backward
direction of the list / array.
Ascending order
0 1 2 3 4 5 6
10 20 15 25 11 1 9
0 1 2 3 4 5 6
10 20 15 25 11 1 9
0 1 2 3 4 5 6
10 20 15 25 11 1 9
0 1 2 3 4 5 6
10 15 20 25 11 1 9
0 1 2 3 4 5 6
10 15 20 25 11 1 9
0 1 2 3 4 5 6
10 15 20 25 11 1 9
0 1 2 3 4 5 6
10 11 15 20 25 1 9
0 1 2 3 4 5 6
1 10 11 15 20 25 9
0 1 2 3 4 5 6
1 10 11 15 20 25 9
0 1 2 3 4 5 6
1 9 10 11 15 20 25
P a g e | 22
P a g e | 23
Example:
import sys
for st in sys.stdin:
# print(st)
sys.stdout.write(st)
# press Ctrl+D to exit to the prompt
Example 2:
import sys
fh=open(r"d:\myprog\poem.txt")
line1=fh.readline()
line2=fh.readline()
sys.stdout.write(line1)
sys.stdout.write(line2)
sys.stderr.write("No Error Occured\n")
fh.close()
# press Ctrl+D to exit to the prompt
Example 3:
import math
import sys
p=math.sqrt(16)
sys.stdout.write(str(p))
P a g e | 24
NOTE: *Go to python shell prompt and write the following command to check
connection object and
>>> import mysql.connector →if no error comes then mysql connector
installed properly
Or
>>> import mysql.connector as mysqlPy →mysql connector may be used
with alias name
passwd=<”password”>
[,database=<database>])
Example -1 : To login to mysql only
>>> mydb=mysql.connector.connect(host="localhost",
user="root",passwd="admin")
OR by suing alias name of mysql connector
>>>mydb=mysqlPy.connect(host="localhost",
user="root",passwd="admin")
Example -2 : To login to mysql and open Database EMPLOYEE>
>>>mydb=mysql.connector.connect(host="localhost", user="root",
passwd="admin",
database=”EMPLOYEE”)
• connect(….) : this function of mysql.connector us used take four parameter
host, user, passwd and database to establish connection to MySQL or any
MySQL database.
• A database connection object (in above i.e. mydb) controls the
connection to the database. It represents a unique session with a
database connected from within a script/program.
• Is_connected() : This function returns True if the connection is
successful.
Syntax: connectionObj.is_connected()
Example: if mydb.is_connected()==True:
print("Connection to MySQLdatabase is successful")
Step-3.2: Extract data from result set after execution of the Queries
using execute()
• fetchall() – It will return all the records retrieved as per query in a tuple
form (i.e. now <data> will be tuple).
Syntax: <data_var>=<cursorObj>.fetchall()
Example: rec=curObj.fetchall()
for k in rec:
print(k)
• fetchone() – It will return one record from resultset (cursor object) as a
tuple or a list. First time it will return the first record, next time it will fetch
the next record and so on. This method returns one record as a tuple: if
there are no more records then it returns ‘None’.
Syntax: <data_var>=<cursorObj>.fetchone()
Example: rec=curObj.fetchone()
print(rec)
• rowcount –The rowcount is a property of cursor object that returns the
number of rows retrieved from the cursor so far.
Syntax: <data_var>=<cursorObj>.rowcount
Example: data=curObj.fetchall()
N=curObj.rowcount #curObj is cursor object (NOT
connection object)
print(“Total number of rows retrieved : “, N) # display total
no. of records
manipulation modules.
REQUIREMENTS
HARDWARE
PROCESSOR
• Pentium 486/PI/PII/PIII/PIV/Core2Due or Higher
Processor
MEMORY
• Main Memory : 2 GB or More
• Secondary Memory : 250 GB or More
OTHER PERIPHERALS:
• printer (for Documentation using
hardcopy)
NETWORKING
• LAN (for module developments)
• INTERNET (for online informations)
SOFTWARE
OPERATING SYSTEM
• GUI : Windows 8.1 OS or Higher (or any GUI OS)
APPLICATION
• Word Processor : MS Word (or any other for
documentation)
• Editor : Python IDE or any other
Editor for python coding
LANGUAGE
• Coding Language : Python 3.6.0 (or higher ver.)
DBMS/RDBMS
• SQL Software : MYSQL 5.5.11 (or higher ver.)
P a g e | 29
Purpose of the Table: This tables is used to store the user detail for login screen.
Code to create:
P a g e | 31
import mysql.connector
To change the current database later, execute a USE SQL
statement or set the database property of the MySQLConnection
instance. By default, Connector/Python tries to connect to a
MySQL server running on the local host using TCP/IP. The host
argument defaults to IP address 127.0. 0.1 and port to 3306.
import datetime
Date and datetime are an object in Python, so when you
manipulate them, you are actually manipulating objects and not
string or timestamps. Whenever you manipulate dates or time,
you need to import datetime function.
P a g e | 33
FUNCTIONS USED IN
THE PROGRAM
def database_setup():
- U sed to cr eate d atab ases w i th i ts t abl es usi ng D D L comma nd.
- The d atabas e i s “e mpl oye e ” an d the tabl es na me i s “de pt”, “em p”.
def connectivity_check():
- U sed to check conn ecti vi ty betw e en mys ql and python .
def show_database_contents():
- U sed to l i st ta bl es i n e mpl oye e data base.
def edit_database():
- U sed to i nse rt, del ete, u pdat e reco rds i n empl o yee data base .
def insert():
- U sed to i nse rt, del ete a nd up date reco rds i n e mpl oyee datab ase.
def delete():
- U sed to del ete r ecords i n em pl oyee datab ase .
def update():
- U sed to up date reco rds i n e mpl oye e dat abase .
def acquire_data():
- U sed to show reco rds fr om e mp an d de pt tabl e .
def empno():
- U sed to show detai l s o f an empl oye e by e mpno .
def ename():
- U sed to show detai l s o f an empl oye e by e name .
def job():
- U sed to show detai l s o f al l em pl oyee s by j ob .
def deptno():
- U sed to show detai l s o f al l em pl oyee s by dep tn o .
def job_wise():
- U sed to show detai l s o f al l em pl oyees j o bw i se.
def deptno_wise():
- U sed to show detai l s o f al l em pl oyees deptn ow i se .
P a g e | 34
im por t os
im por t da tetim e
now = da tetim e. date tim e.n ow ()
m ydb=m ys ql.co nn ect or .con nec t(h ost ="loc al host" ,user ="r o ot", passw d="a dm in", d
ataba se=" em ploy ee")
n=i np ut( )
if n in[' y' ,' Y ' ]:
m ycur s or .exec ute ("IN S E R T IN T O D EP T V A LU E S (10, ' A C C OU N T IN G' , ' N E W
Y OR K ' );")
m ycur s or .exec ute ("IN S E R T IN T O D EP T V A LU E S (20, ' R E S E A RC H ' , ' DA LLA S ' );")
m ycur s or .exec ute ("IN S E R T IN T O D EP T V A LU E S (30, ' S A LE S ' , 'C H IC A GO' );")
m ycur s or .exec ute ("IN S E R T IN T O D EP T V A LU E S (40, ' OP E R A T IONS ' , ' B OS T ON' );")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7369, ' S MIT H ' , ' C LE R K' , 7902,
' 1990-12 -17' , 80 0, N U LL , 20 );")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7499, ' A LLE N ' , ' S A LE S MA N ' , 7698,
' 1981-02 -20' , 16 00, 3 00, 3 0);")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7521, ' W A R D ' , ' S A LES MA N ' , 7698,
' 1981-02 -22' ,125 0, 50 0, 30 );")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7566, ' JON E S ' , ' MA N A GE R' , 7839,
' 1981-04 -02' , 29 75, N U L L, 20 );")
P a g e | 35
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7654, ' MA R T IN ' , ' S A LE S MA N' , 7698,
' 1981-09 -28' , 12 50, 1 400, 30);" )
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7698, ' B LA K E ' , ' MA N A GE R ' , 7839,
' 1981-05 -01' , 28 50, N U L L, 3 0);")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7782, ' C LA R K ' , ' MA N A GE R ' , 7839,
' 1981-06 -09' , 24 50, N U L L, 10 );")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7788, ' S C OT T' , ' A N A LY ST ' , 7566,
' 1982-12 -09' , 30 00, N U L L, 20 );")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7839, ' K IN G' , ' P R E S IDE N T' , N U LL,
' 1981-11 -17' , 50 00, N U L L, 10 );")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7844, ' T U R N E R ' , ' S A LE S MA N' ,
7698, ' 198 1 -0 9-08' , 1 500, 0, 30 );")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7876, ' A D A MS ' , ' C LE R K ' , 7788,
' 1983-01 -12' , 11 00, N U L L, 20 );")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7900, ' JA ME S ' , ' C LE R K ' , 7698,
' 1981-12 -03' , 95 0, N U LL , 30 );")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7902, ' FOR D ' , ' A N A LY S T' , 7566,
' 1981-12 -03' , 30 00, N U L L, 20 );")
m ycur s or .exec ute ("IN S E R T IN T O E MP V A LU E S (7934, ' MIL LE R ' , ' C LE R K ' , 7782,
' 1982-01 -23' , 13 00, N U L L, 10 );")
m yd b.com m it( )
pr in t("V A LU E S S U C C E S S FU LLY E N TE RE D ")
m ydb=m ys ql.co nn ect or .con nec t(h ost ="loc al host" ,user ="r o ot", passw d="a dm in", d
ataba se=" em ploy ee")
m ycur sor =m yd b.c ur sor ()
pr int ("___ ____ ____ ____ ____ ____ ____ ___ ______ ____ ____ ____ ____ _E MP LOY E E
D A T A B SE ________ ____ ____ ____ _____ ____ _ ______ ____ ____ ____ ___ \ n\n\ n")
pr int (" * * * * ** * ** *** * ** ** * ** ** ** ** * ** ** ** * ** ** ** ")
pr int (" D E P T T A B LE ")
pr int (" * * * * ** * ** *** * ** ** * ** ** ** ** * ** ** ** * ** ** ** ")
pr int (" \t\ t-- --- ---- --- --- --- --- --- --- --- ---- --- --- -- ---- --- --- ---- --- --- --- --- --- --- --- ---- --- -- " )
pr int (" \t\ t E MP N O E N A ME JOB MGR D OJ S A LA R Y C O MM
D E P T N O")
pr int (" \t\ t-- --- ---- --- --- --- --- --- --- --- ---- --- --- -- ---- --- --- ---- --- --- --- --- --- --- --- ---- --- -- " )
for i i n p :
pr i nt(" \ t\t",i [0]," \ t",i[1 ],(( 8 -le n(i [1]) )* " "),"",i[2] ,((1 0 -le n(i [2]) )* "
"),"",i[3] ," \t",i[ 4]," \ t",i[5 ]," \t",i [6]," \ t ",i[ 7])
pr int (" \t\ t-- --- ---- --- --- --- --- --- --- --- ---- --- --- -- ---- --- --- ---- --- --- --- --- --- --- --- ---- --- -- " )
def e dit_ dat aba se( ):
pr int (" \t\t \t\t\ t |* * * * ** * ** ** ** * ** ** ** * ** ** ** * ** ** * ** * |")
pr int (" \t\t \t\t\ t | 1. IN S E R T R E C OR D |")
pr int (" \t\t \t\t\ t | 2. D E LE T E R E C OR D |")
pr int (" \t\t \t\t\ t | 3. U P D A T E R E C OR D |" )
pr int (" \t\t \t\t\ t |* * * * ** * ** ** ** * ** ** ** * ** ** ** * ** ** * ** * |")
n=i nt( inp ut(" \t\t\ t\t\ t\t E n ter yo ur cho ice :" ))
pr int (" \t\t \t\t\ t\t |* * * ** ** * ** ** ** * ** ** ** * ** ** ** * ** * ** ** | \n")
if n == 1:
in ser t()
if n == 2:
d elet e()
if n == 3:
u pda te( )
def i nser t( ):
m ydb=m y sql.c on nec tor .co nne ct( hos t="l o calho st", user ="r oo t",p assw d="a dm in",
data base ="E MP LOY E E ")
pr int (" \n E n ter th e de tails of the em plo ye e w hose r ecor d s t o be inser t ed: \ n")
en o=in t(i np ut("E n ter em plo yee N o:"))
nam =i npu t("E n ter em ploy ee nam e:")
jb=i np ut("E n ter em pl oyee j ob :")
pr int ("E nter D at e o f Joi nin g as d d:m m :yy y: ");
d=i nt( inp ut(" dd : "))
m =int (in put ("m m : "))
y=i nt(i np ut(" yyyy :"))
dj= dat etim e.d ate (y,m ,d) # dat eti m e.date( 1981 , 4, 2 )
# dj = d ate tim e.da tetim e( y,m ,d)
# dj = dj .str ftim e (' %Y -%m - %d' )
# pr in t(d j)
sl=f loa t(in pu t("E nt er S alar y:"))
dn o=i nt(i np ut("E n ter de pt no N o :"))
m ycur sor .ex ecu te("IN S E R T IN T O E MP (empno, enam e, job , d oj, sa l, com m , de pt no)
V A LU E S ({ } , '{ }' , ' {} ' , ' {} ' , {} ,{ } , { } )".for m at(en o, nam , j b, dj , sl, ' N U LL' , dno ))
m ydb.c om m it() # T o sa ve a bov e D ML tr a nsact ion s t o th e da tab ases ot her w ise w ill
not save per m ane ntly
en o=in t(i np ut("E n ter the em pn o w hich r ec or d yo u w ant t o u pda te: " ))
qr ="S E LE C T * FR OM E MP W H E R E em pno={ } ".for m at(eno)
pr int (qr )
m ycur sor .ex ecu te( qr )
r ec=m ycur s or .fetc hall ()
pr int (" \n Ol d R ec or d is foll ow s: ")
for k i n r ec:
pr in t(k )
def em p no ():
m ycon =m ysql. co nnec tor .c onn ect (ho st="l ocalh ost" , us er ="r oot", passw d=" adm in",
data base ="em pl oyee" )
m ycon =m ysql. co nnec tor .c onn ect (ho st="l ocalh ost" , us er ="r oot", passw d=" adm in",
data base ="em pl oyee" )
def j ob( ):
m ycon =m ysql. co nnec tor .c onn ect (ho st="l ocalh ost" , us er ="r oot", passw d=" adm in",
data base ="em pl oyee" )
P a g e | 39
# __ MA IN ___
# LOGIN P A S S W OR D S C R E E N
ctr =0
flag= 0
w hile ctr <3:
im por t m ysq l.co nn ect or
pr int (" \t\t \t\t\ t |* * * * ** * ** ** ** * ** ** ** * ** ** ** * ** ** * ** * |")
pr int (" \t\t \t\t\ t | LOG IN S C R E E N OF S YS T E M |")
pr int (" \t\t \t\t\ t |* * * * ** * ** ** ** * ** ** ** * ** ** ** * ** ** * ** * |")
user _ nam e=i npu t(" \t \t\t\ t\t\ t E nter U s er N am e: ")
ps d=in pu t(" \t\ t\t\ t\t\ t E nter P as sw or d: ")
pr int (" \t\t \t\t\ t |* * * * ** * ** ** ** * ** ** ** * ** ** ** * ** ** * ** * |")
m ydb=m ys ql.co nn ect or .con nec t(h ost ="loc al host" ,user ="r o ot", passw d="a dm in", d
ataba se="P A S S ")
m ycur sor =m yd b.c ur sor ()
sql ="S E LE C T uid,un am e,upw d fr om user "
m ycur sor .ex ecu te(s ql)
ctr =c tr +1
for i i n m ycur s or :
# pr int(" \t\t",i [0]," \t",i[ 1], " \ t",i[2 ])
if (i[1 ]== user _ nam e)a nd(i [2] == psd ):
pr int (" \t\t\ t\t\ t | S ucc essf ully log in ...! !! |")
pr int (" \t\t\ t\t\ t |* * * * ** * ** ** ** ** * ** ** ** * *** * ** ** * ** ** | \n\n\n\ n\n")
flag =1
br eak;
if fl ag= =0 a nd ctr <3:
pr in t(" \t \t\t\ t\t | IN V A LID U ID OR P A S S W OR D ...!!! |")
pr in t(" \t \t\t\ t\t | T R Y A GA IN (MA X 3 T IME S ) ...!!! |")
pr in t(" \t \t\t\ t\t |* * * ** ** * ** ** ** * ** ** ** * ** ** *** * ** ** * * | \n")
elif flag ==0 an d ctr > =3:
pr in t(" \ n\t\t \t\tS OR R Y ..!! S Y S T E M E R R OR C ON T A C T Y OU R V E ND E R ..!! ")
ex it()
else :
br ea k;
# MA IN ME N U
pr int(" ...... ......... ......... .W elco m e S ir T o Main
P r ogr am ................. ....... \ n\n\ n\n" )
pr int(" ...... ......... .D evel ope d B Y Mitr abha nu P r ad han, C lass X II
S C ............... \ n\n\ n\n" )
w hile T r ue:
pr int (" \t\t \t\t\ t |* * * * ** * ** ** ** * ** ** ** * ** ** ** * ** ** * ** * |")
pr int (" \t\t \t\t\ t | E MP LOY E E MA N A GE ME N T S YS T E M |")
pr int (" \t\t \t\t\ t |* * * * ** * ** ** ** * ** ** ** * ** ** ** * ** ** * ** * |")
pr int (" \t\t \t\t\ t | 1. D A T A B A S E S ET U P |" )
pr int (" \t\t \t\t\ t | 2. C ON N E C T IV IT Y C H EC K |")
P a g e | 41
TESTING OF THE
PROGRAM
Departments.
CONCLUSIONS
working successfully. The code, test plan & other documents are used to
solve the total process of the system. Any user can test this project easily
but there may be some error that can be negligible and that will not affect
the system or the general user. Any type of difficulty will be find that should
be error free by the system administrator. The design of the system is very
MAINTENANCE
INSTALLATION PROCEDURE
DOCUMENTATION:
The program provides proper documentation
with clarity of coding.
MAINTENANCE
CERTIFICATE
This is to certify that Mitrabahanu Pradhan, student of class
Date: Date:
P a g e | 63
BIBLIOGRAPHY