Anjeev Singh Academy

Anjeev Singh Academy

CBSE XII Computer Science 083 Practical Question Paper Set 5 – Download in Word

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

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

Are you looking for Answer Key? Please Scroll to the Down 👇

Answer Key of Set 5 Practical Examination Question Paper

Answer Key Set – 5

Q1. LAB TEST                                                                                                                       [8+4=12]

  A. 1) Write a function in Python that counts the number of words which does not have vowel character present in a text file “STORY.TXT”   

Answer:

#Creating a Text File - story.txt
fout = open("story.txt", 'w')
fout.write("Hello Hw are You\n")
fout.write("I am fine\n")
fout.write("Thank y \n")
fout.close()

#Method – 1

# Solution of Que A. 1
#-----------------------------------
#Method - 1
#-----------------------------------
fin = open("story.txt", "r")
count = 0
text = fin.read()
for word in text.split():
        found = True
        for ch in word:
            if ch in 'aeiouAEIOU':
                found = False
        if found == True:
            count += 1

print("Number of words not having vowel is/are : ", count)
fin.close()

#Method – 2

#-----------------------------------
#Method - 2
#-----------------------------------
fin = open("story.txt", "r")

line = ' '
count = 0
while line:
    line = fin.readline()
    
    for word in line.split():
        found = True
        for ch in word:
            if ch in 'aeiouAEIOU':
                found = False
        if found == True:
            count += 1
print("Number of words not having vowel is/are : ", count)
    
fin.close()

Output:

            Number of words not having vowel is/are :  2

2)   Write function AddDrug() to write the Records of Drug(DrugId, Name, Price) in a binary file name “drug.dat”, and Write a function Display() to show those records from a binary which price is less than 50.

Answer:

#--------------------------
#Que No A 2 - Binary File
#--------------------------

import pickle

def AddDrug():
    fout = open("drug.dat", "wb")           # opening of file
    while True:
        rec = {}
        did = int(input("Enter Drug Id : "))
        name = input("Enter Drug Name : ")
        price = float(input("Enter Drug Price : "))

        rec['did'] = did
        rec['name'] = name
        rec['price'] = price

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

        print()
        choice = input("Want to add more y/n :")
        if choice.lower() != 'y':
            break
    fout.close()

def Display():
    fin = open("drug.dat", "rb")
    try:
        while True:    # loop is required to read all records
            rec = pickle.load(fin)# read only one record
                                  # at a time refered by fin file object
            if rec['price'] < 50:
                print(rec)
    except:
        fin.close()

#Always call function after writing all functions

AddDrug()
Display()

Output:

Enter Drug Id : 101

Enter Drug Name : Paracetamol 500mg

Enter Drug Price : 25.00

Want to add more y/n :y

Enter Drug Id : 102

Enter Drug Name : Becosule

Enter Drug Price : 12.00

Want to add more y/n :y

Enter Drug Id : 103

Enter Drug Name : Amoxyceline

Enter Drug Price : 150.00

Want to add more y/n :y

Enter Drug Id : 104

Enter Drug Name : Betonovat

Enter Drug Price : 65.00

Want to add more y/n :y

Enter Drug Id : 105

Enter Drug Name : SavlonSticker

Enter Drug Price : 35.00

Want to add more y/n :n

{‘did’: 101, ‘name’: ‘Paracetamol 500mg’, ‘price’: 25.0}

{‘did’: 102, ‘name’: ‘Becosule’, ‘price’: 12.0}

{‘did’: 105, ‘name’: ‘SavlonSticker’, ‘price’: 35.0}

OR

A list contains following record of a student: [StudentName, Class, Section, MobileNumber]

Write the following user defined functions to perform given operations on the stack named XII_A:

(i)   pushElement() – To Push an object containing name and mobile number of students who belong to class xii and section ‘a’ to the stack

(ii)  popElement() – To Pop the objects from the stack and display them. Also, display “Stack Empty” when there are no elements in the stack.

If the lists of students details are:

[“Rajveer”, “99999999999”,”XI”, “B”]         [“Swatantra”, “8888888888”,”XII”, “A”]

[“Sajal”,”77777777777”,”VIII”,”A”]            [“Yash”, “1010101010”,”XII”,”A”]

The stack XII_A should contain

[“Swatantra”, “8888888888”  ]                       [“Yash”, “1010101010”]

The output should be:

[“Yash”, “1010101010”]      [“Swatantra”, “8888888888”]    Emtpy Stack

Answer:

#Que No A 2 - OR (STACK)
students = [
        ["Rajveer", "99999999999","XI", "B"],
        ["Swatantra", "8888888888","XII", "A"],
        ["Sajal","77777777777","VIII","A"],
        ["Yash", "1010101010","XII","A"] ]

XII_A = []
def pushElement():
        for st in students:
                if st[2] == 'XII' and st[3] == 'A':
                        rec = [st[0], st[1]]
                        XII_A.append(st)

def popElement():
        for i in range(len(XII_A)+1):
                if XII_A == []:
                        print("Empty Stack")
                else:
                        st = XII_A.pop()
                        print(st)

#__ main block ___
print("PUSHING Students\n")
pushElement()

#to invoke pop for six times
print("\nPOPPING")
popElement()

Output:

PUSHING Students

POPPING Student of Class XII A

[‘Yash’, ‘1010101010’, ‘XII’, ‘A’]

[‘Swatantra’, ‘8888888888’, ‘XII’, ‘A’]

Empty Stack

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

import  mysql.connector as sqltor  		
mycon = sqltor.connect( ___________________ ) 	#Statement 1
cursor = mycon.cursor( )
cursor.execute(______________________ )  			#Statement 2
data = _________________  						                        #Statement 3
for rec in data:
     print ( rec )
      _____________________						                    #Statement 4
 mycon.close( )

DrugIDDrugNamePricePharmacyNameLoc
101PARACETAMOL15.50R K PHARMACYDELHI

a. Complete the Statement 1 to write appropriate missing parameter and values. [ User Id is root and Password is Root123]
b. Write the Statement 2, to fetch drugName, and price from table Drug in descending order of price. c. Complete the Statement 3, to fetch only three records from the resultset.
d. What statement you will write in place of statement #2 to insert one more record in table Drug, as well as in statement #4, to make your changes permanent in the table Drug.

Answer:

import  mysql.connector as sqltor                  

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

 (b) cursor.execute(SELECT drugName, Price FROM STUDENT ORDER BY Price DESC)                                                                           # Statement 2

(c)  data = cursor.fetchmany(3)          # Statement 3

(d) #Statement 2

cursor.execute(“INSERT INTO DRUG VALUES (105, “Becosule”, 25.00, “A K Pharma”, “New Delhi” ) ”)

# Statement 4 mycon.commit()                      

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

Scroll to Top