# This program holds basic operations performed by list such as 'Adding new entry', 'Inserting list element', 'Extending list'
# List operations
stud_names=[]
stud_id=[]
cousins=['Vivek','Veerain','Priyanka','Shirisha','Shravya']
friends=['Abhi','pri','Sammmmmy','Sai','Shaaaa','hemu','adii','sowji','murali','venky','Sanndy']
names=[]
print '***** What action you would like to do ***** \n'
print '1. Add New Student name & id\n'
print '2. Insert student details \n'
print '3. Extend lists \n'
operation=input('Enter the operation you would like to perform: ')
if operation==1:
# Use of 'append' keyword
sname=raw_input('Enter the student name: ')
stud_names.append(sname)
cousins.append(sname)
sid=input('Enter student id: ')
stud_id.append(sid)
print('Students:',stud_names)
print('Student Id:',stud_id)
elif operation==2:
# Use of 'insert' keyword
sindex=input('Enter the index position you want to insert the name: ')
sname=raw_input('Enter the student name: ')
stud_names.insert(sindex,sname);
cousins.insert(sindex,sname) # This is just another example
print(cousins)
elif operation==3:
print '**************** Full list of cousins and friends would be ************** \n'
# Use of 'extend' keyword
names.extend(cousins)
names.extend(friends)
print(names)
print('\n sorted names list: ',names.sort())
print('\n Length of names list is :',len(names)) # Use of 'len' function
search=raw_input('Enter the name you would like to Search: ')
# Use of 'in'& 'not in' keyword
if search in names:
print 'Search Successful'
elif search not in names:
print 'Search unsuccessful'
else:
Labels: Python Programming
0 Comments:
Subscribe to:
Post Comments (Atom)