Beruflich Dokumente
Kultur Dokumente
Date (Assign)
: Practice Lab
: Practice Lab
Total Time
: 2 hrs.
Week
: First
Lab (A or B)
:A
_________________________________________________________________________________________________
INSTRUCTIONS:
1. Unprofessional conduct, such as an abuse of USF computer privileges (unauthorized access), or a Violation of academic integrity
(plagiarism or fraud), will result in the student receiving a failing grade.
2. Work in singles.
3. Late submission will be evaluated from half of total marks.
5. Platform:
Use Python, Either on window or Linux platform.
____________________________________________________________________________________________________________________
Tutorial #1:
Open StartProgramPythonIDLE (GUI) and practice on following commands:
1.
2.
Record representation
Let us take an example; a student can have an enrollment number, name, branch, batch etc. What are the different ways to manage
record of a student and how can we iterate the records of a student. There are different ways of record management and some of them
are:
a.
Using Lists
b.
Database List
c.
Field Labels
d.
Using Dictionaries
e.
Nested Structures
f.
Dictionaries of dictionaries
Using Lists:
(i)
>>> a=['text',23,'alpha25']
(ii)
>>> a
(iii)
>>> a[0]
(iv)
>>> a[1]
(v)
>>> a[2]
(vi)
>>> a[3]
(vii)
(viii)
>>> student[0].split()[-1]
(ix)
>>> student[0].split()[0]
(x)
>>> len(student)
(xi)
>>> student[0].upper()
(xii)
(xiii)
>>> student[0].ljust(100)
(xiv)
>>> student[0].rjust(100)
(xv)
>>> student[0].center(100)
(xvi)
>>> student[0].zfill(100)
(xvii)
>>> student[0].replace('ajay','vijay')
(xviii)
>>> student
b. Database List:
Database is group of lists.
(i)
>>> list1=['student1',21,'batch1']
(ii)
>>> list2=['student2',22,'batch2']
(iii)
>>> list1
(iv)
>>> list2
(v)
>>> database=[list1,list2]
(vi)
c.
(vii)
>>> database[1][0]
(viii)
>>> database[1][2]
(ix)
>>> database[0][1]
(x)
(xi)
>>>age
(xii)
(xiii)
>>> pays
(xiv)
>>> database.append(['student3',23,'batch3'])
(xv)
>>> database
(i)
(ii)
(iii)
>>> bob[NAME]
(iv)
Field Labels
# [0, 1, 2]
d. Using Dictionaries
Using list based dictionaries; you can attach values to the field names.
(i)
(ii)
(iii)
>>> list1['name']
(iv)
>>> list1['age']+=1
(v)
>>> list1['age']
e. Nested Structures
(i)
>>> list1={'name':{'first':'ADARSH','Last':'Kumar'},
'age':27,
'job':['senior','lecturer'],
'pay':(400,500)}
3.
>>> a=['hello']
4.
>>> a[0]
5.
>>> a[0][1]
6.
>>> a[0][0]
7.
>>> a[0][-1]
8.
>>> a[0][-3]
9.
File Handling
a.
(ii)
>>> list1['name']
(iii)
>>> list1['name']['Last']
(iv)
>>> db={}
(v)
>>> db['list1']=list1
(vi)
>>> db['list2']=list2
(vii)
>>> db['list1']['list2']
(viii)
>>> db['list1']
(ix)
>>> db
b.
print line
c.
stack = []
def pushit():
stack.append("A")
def popit():
if len(stack) == 0:
print 'Cannot pop from an empty stack!'
else:
print 'Removed [', 'stack.pop()', ']'
def viewstack():
print stack
pushit()
viewstack()
popit()
viewstack()
________________________________