Anjeev Singh Academy

CBSE XII Computer Science 083 Practical Question Paper Set 2 – Download

AISSCE XII Computer Science 083 – Practical Question Paper Set #2 – Download Word File

All India Senior Secondary Certificate Examination
XII Computer Science 083 – Practical Question Paper Set #2

Answer Key of Set – 2 Practical Examination Question Paper

ANSWER KEY – SET 2

Q1. LAB TEST                                                                                            [8+4=12]

A. 1) Write a Python Program read a text file line by line and display line started with ‘T’.                       (4)

Answer:

            #Que No – #A 1

#Creating Story.txt file

fout = open(“story.txt”, ‘w’)

fout.write(“Hello How are You\n”)

fout.write(“I am fine\n”)

fout.write(“Thankyou\n”)

fout.write(“This is too much\n”)

fout.write(“What happend\n”)

fout.close()

#Reading line by line and checking

fin = open(“story.txt”, “r”)

line = ‘ ‘

while line:

    line = fin.readline()

    if line != None and line[0] == ‘T’:

        print(line)

fin.close()

Output:

Thankyou
This is too much

OR

Write a function to WriteRec() to write the 5 Employee Records (id, name, salary) in a binary file name “Emp.dat” and ReadRec() function to read the all records from a binary file “Emp.dat” and display  them.

Answer:

# Solution of Que A. 1 (OR)

#———————————–

# Binary file

import pickle

def WriteRec():

    fout = open(“Emp.dat”, “wb”)           # opening of file

    for i in range(5):

        rec = []

        id = int(input(“Enter Admission Number : “))

        name = input(“Enter Name : “)

        salary = float(input(“Enter Fee : “))

        rec = [id, name, salary]

        pickle.dump(rec, fout)        #write one record in a file refered by fout

    fout.close()

def ReadRec():

    fin = open(“Emp.dat”, “rb”)

    try:

        while True:                       # loop is required to read all records

            rec = pickle.load(fin)     # read only one record

                                                   # at a time referred by fin file object

            print(rec[0], rec[1], rec[2])

    except:

        fin.close()

#Always call function after writing all functions

WriteRec()

ReadRec()

Output:

Enter Admission Number : 1

Enter Name : a

Enter Fee : 2500

Enter Admission Number : 2

Enter Name : b

Enter Fee : 1500

Enter Admission Number : 3

Enter Name : c

Enter Fee : 2560

Enter Admission Number : 4

Enter Name : d

Enter Fee : 3500

Enter Admission Number : 5

Enter Name : e

Enter Fee : 5000

1 a 2500.0

2 b 1500.0

3 c 2560.0

4 d 3500.0

5 e 5000.0

2) Write a python program to create a stack of student’s record which contains [admo, name].             (4)

  • Write function PUSH to add record in to the stack and
  • Write function DISPLAY to display those students whose name is started with ‘A’       

Answer:

# STACK

student = []   #global variable

def PUSH():

    admno = int(input(“Enter Admission No :”))

    name = input(“Enter Name : “)

    rec = [admno, name]

    student.append(rec)

def DISPLAY():

    if student == []:

        print(“Empty Stack”)

    else:

        for st in student:

            if st[1][0] == ‘A’:

                print(st[0], st[1])

#to invoke push for five times

print(“PUSHING”)

for a in range(5):

    PUSH()

print(“DISPLAYING RECORDS”)

DISPLAY()

Output:

PUSHING

Enter Admission No :1

Enter Name : Amit Sharma

Enter Admission No :2

Enter Name : Rajesh Singh

Enter Admission No :3

Enter Name : Anil Thakur

Enter Admission No :4

Enter Name : Yashashvi

Enter Admission No :5

Enter Name : Anju

DISPLAYING RECORDS

1 Amit Sharma

3 Anil Thakur

5 Anju

B.  A table Student is created in the database School. The details of table are given below.                   (4)

StuIDNameClassTotalGrade
ST/12Tanmay12 C499A+

import  mysql.connector as sqltor                

      mycon = sqltor.connect( _______,  user = “root”, _________, database = ___________ )        #1

cursor = mycon.cursor( )

      cursor.execute(______________________ )                                                                            #2

      data = _________________                                                                                                   #3

      for rec in data:

                   print ( rec )

      _____________________                                                                                                      #4

       mycon.close( )

a. Complete the statement #1 to write appropriate missing parameter and values.

      b. Write the statement #2, to fetch Name, Class, Grade from table Student who have scored less than 400.

      c. Complete the statement #3, to fetch all records from the result set.

 d. What statement you will write in place of statement #2 to insert one more record in table Student, as well as in statement #4, to make your changes permanent in the table Student.

StuIDNameClassTotalGrade
ST/15Amrit12 D496A+

Answer:

import  mysql.connector as sqltor                

      mycon = sqltor.connect( host = “localhost”,  user = “root”, passwd = “root”, database = “School” )    # Statement 1

cursor = mycon.cursor( )

      cursor.execute(“SELECT NAME, CLASS, GRADE FROM STUDENT WHERE TOTAL < 400”)                                                                           # Statement 2

      data = cursor.fetchall()                                             # Statement 3

      for rec in data:

                   print ( rec )

       mycon.close( )

(d) #Statement 2

cursor.execute(“INSERT INTO STUDENT VALUES (“ST/15”, “AMRIT”, “12 D”, 496, “A+”)”)

# Statement 4mycon.commit()          

Sorry! You cannot copy content of this page. Please contact, in case you want this content.

Scroll to Top