0% found this document useful (0 votes)
32 views

CSC Assignment

Uploaded by

beastboylove bbl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

CSC Assignment

Uploaded by

beastboylove bbl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Class XII – Computer.

Sc Assignment

1. A binary file “vehicle.dat” has structure [RegNo, Type, Make, Year].


a. Write a user defined function AddVahan() to input data for a vehicle and add to “vehicle.dat” file.
b. Write a function CountVahan(Type) in Python which accepts the Type of the vehicle as the
parameter and count and return the number of vehicles of the given Type.

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".

3. A binary file “player.dat” has structure (PlayerId, Name, Team, StrikeRate).


Write a function ShowPlayer() in Python that would read contents of the file and display the details of
those players whose Team is “India” and StrikeRate is above 50. Also display the total number of such
players.

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

5. Predict the output of the following code:

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)

a) Name the module he should import in Line 1.


b) Write a code to read the fields (column heading) once from fields list in Line2.
(c) Write a code to delete the row from row list in Line3.

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 :

For example : Consider the following dictionary


S={"AMIT":[92,86,64],"NAGMA":[65,42,43],"DAVID":[92,90,88]}
The output should be :
AMIT – B NAGMA – C DAVID – A

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.

You might also like