CS Lab Assignment
CS Lab Assignment
CS Lab Assignment
1. Write a program to define a function COUNT( S ) that accept a string and count total number of
uppercase characters, lowercase characters and digits present in it.
2. WAP to enter a list of words and define a function LASTOFF( ) that accept the list and create a new
list with last character removed from each word.
Example : if L = [„BOOKS‟, „ARE‟, „BEST‟], then after program N = [„BOOK‟, „AR‟, „BES‟]
3. Write a program to define a function COUNT( T ) that accept a nested tuple of numbers and count the
total numbers present in each element.
For Ex: If T = ((2, 1, 9), (5, 6, 1, 8), (8, 3, 1, 5)), then output should be:
element 1 = 3
element 2 = 4
element 3 = 4
5. Write the definition of a function Sum5(L) in Python, which accepts a list L of integers and displays
the sum of all such integers from the list L which end with the digit 5.
For example, If the list L is passed [ 125, 15, 13, 35, 23]
then the function should display the sum of 125, 15, 35, i.e. 175 as follows :
Sum of integers ending with digit 5 = 175
6. Write a program to define a function MarksDetails( ) that accept a dictionary of n elements having
student name as key and total marks as value. Print the entire dictionary content along with the name
of the student having highest marks.
7. WAP to define a function LShift (L,n) that accepts a list Arr of numbers and a number n by which all
elements of list are shifted to left.
For example,
L= [10, 20, 30, 40, 12, 11] and n=2.
Output: Arr=[30,40,12,11,10,20]
8. Write a function CountLine() in python to count the number of lines in a text file „myfile.txt’ which
ends with alphabet ‘a’or „i‟.
9. Define a function displayWords ( ) in Python to read the contents of the text file “India.txt” and
display and count words “India” or “india” present in it.
10. Write a function Disp_Word ( ) in python to read lines from a text file „SAMPLE.TXT‟ and display
those words which are less than 5 characters long.
12. A binary file “Stusent.dat” stores the records having their structure as [AdmNo, Name, Marks] ,
Define a function ReadData ( ) to read and display the records of the students whose marks is greater
than 400.
13. A CSV file “StdRecords.csv” has structure [AdmNo, Name, Marks], Write a user defined function
CreateCSV () to input data for a record and add to StdRecords.csv.
14. A CSV file “EMPDETAILS.CSV” stores the records having their structure as
[EMPNo, EName, SALARY], Define a function DISPLAY ( ) to read and display the records of the
employee‟s whose salary is less than 30000.
15. Coach Amit Kumar stores the races and participants in a dictionary. Write a program, with separate
user defined functions to perform the following operations:
Push the names of the participants of the dictionary onto a stack, where the distance is more
than 100.
Pop and display the content of the stack. For example: If the sample content of the dictionary
is as follows: Races ={100:'Varnika', 200 :'Sumit', 400:'Rahul', 800:'Ankit'}