CSC Assignment
CSC Assignment
Sc Assignment
2. Write a user defined function in Python named Puzzle(W,N) which takes the argument W as an
English word and N as an integer and returns the string where every Nth alphabet of the word W is
replaced with an underscore ("_").
For example : if W contains the word "TELEVISION" and N is 3, then the function should return
the string "TE_EV_SI_N". Likewise for the word "TELEVISION" if N is 4, then the function
should return "TEL_VIS_ON".
4. Alam has a list containing 10 integers. You need to help him create a program with separate user
defined functions to perform the following operations based on this list.
● Traverse the content of the list and push the even numbers into a stack.
● Pop and display the content of the stack.
For Example: If the sample Content of the list is as follows:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
Sample Output of the code should be: 38 22 98 56 34 12
6. Coach Abhishek stores the races and participants in a dictionary. Write a program, with separate user
defined functions to perform the following operations:
a. Push() Push the names of the participants of the dictionary onto a stack, where the distance is more
than 100.
b. PoP() Pop and display the content of the stack.
For example:
If the sample content of the dictionary is as follows: Races ={100:'Varnika', 200 :'Jugal', 400:'Kushal',
800:'Minisha'}}
The output from the program should be: Minisha Kushal Jugal
7. Ashok Kumar of class 12 is writing a program to create a CSV file “cust.csv” with custid, custname
and mobile no and search custname and delete the record. He has written the following code. As a
programmer, help him to successfully execute the given task.
import _______ # LINE1
record = list()
custname= input("Please enter a customer name to delete:")
with open('cust.csv', 'r') as f:
data = csv._______(f) # LINE2
for row in data:
record.append(row)
for field in row:
if field == custname:
record.____(row) #LINE3
with open('cust.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(record)
8. Write a user defined function in Python named showGrades(S) which takes the dictionary S as an
argument. The dictionary, S contains Name:[Eng,Math,Science] as key:value pairs. The function
displays the corresponding grade obtained by the students according to the following grading rules :
9. Write a function Accept() that accepts a filename of a text file and print the file’s longest line.
10. Write a program that copies a text file “source.txt” onto “target.txt” barring the lines starting with a “@” sign.
11. Following code is written to update a record in a file opened with following code:
import pickle
fin = open(“stu.dat”, “rb+”)
Try:
while True:
_________ = fin.tell() # Line 1
stu = picke.load(fin)
if stu[‘Marks’] in [92, 93, 94]:
stu[‘Marks’] + = 3
fin. _______ ( ________ ) # Line 2
pickle.dump(stu, fin)
Except:
:
Fill in the blanks in Lines 1 and 2 to complete the code.
12. Write program to increase the salary by Rs. 2000 of the employee having empno as 1251 in the file emp.dat.