G12 CS Worksheet
G12 CS Worksheet
G12 CS Worksheet
5. Julie has created a dictionary containing names and marks as key value
pairs of 6 students. Write a program, with separate user defined functions
to perform the following tasks.
(a) Push the keys (name of the student) of the dictionary into a stack,
where the corresponding value (marks) is greater than 75.
(b) Pop and display the content of the stack.
For example, if the sample content of the dictionary is as follows:
R={“OM”:76, “JAI”:45, “BOB”:89, “ALI”:65, “ANU”:90, “TOM”:82}
Then, the output from the program should be:
TOM
ANU
BOB
OM
1
6. Write a python function CSVCOPY() to take sourcefile, targetfile as
parameter and create a targetfile and copy the contents of sourcefile to
targetfile.
7. Write a Python function SNAMES() to read the content of file emp.csv and
display the employee record whose name begins from “S” also show no. of
employee with first letter “S” out of total record.
Consider the following CSV file (emp.csv):
1, Peter, 3500
2, Scott, 4000
3, Harry, 5000
4, Michael, 2500
5, Sam, 4200
Output should be:
2, Scott, 4000
5, Sam, 4200
Number of names starting with “S” are: 2/5
addInCsv('Note Book',45,100)
addInCsv('Text Book',60,150)
addInCsv('Ball Pen',10,100)
addInCsv('Pencil', 5,200)
readFromCsv() #Line 5
(a) Name the module he should import in Line 1.
(b) Which mode should be mentioned in Line 2, to open the file to add
data into it?
2
(c) Fill in the blank in Line 3 to close the file.
(d) Fill in the blank in Line 4 to read the data from a csv file.
(e) Write the output he will obtain while executing Line 5.