Cst362 Draft Scheme
Cst362 Draft Scheme
PART A
Answer all questions, each carries 3 marks. Marks
Semantics - 1.5
Page 1of 9
0300CST362052203
OR
import os
file_exists=os.path.isfile('./final_data.csv')
Page 2of 9
0300CST362052203
Decryption: 3.5
b) count = 0 (7)
inputFile = open("myfile.txt", 'r')
for line in inputFile:
wordlist = line.split() File opening+line fetching -4
for word in wordlist:
if len(word) == 4:
count += 1
print("There are", count, "lines.") Counting -3
Page 3of 9
0300CST362052203
OR
14 a) 1. def mean(lyst): (7)
theSum = 0
if len(lyst) == 0
return 0
for number in lyst:
theSum += number
return theSum / len(lyst) -2
2. mode
def mode(lyst)
if len(lyst) == 0
return 0
lyst.sort()
midpoint = len(lyst) // 2
print("The median is", end = " ")
if len(lyst) % 2 == 1:
return(lyst[midpoint])
else:
return((lyst[midpoint] + lyst[midpoint - 1]) / 2) -3
3. Mode
def mode(lyst):
counts = {}
for item in lyst:
if item in counts:
counts[item] += 1
else:
counts[item] = 1
Page 4of 9
0300CST362052203
res = False
for idx in range(len(test_list) - len(sublist) + 1):
if test_list[idx : idx + len(sublist)] == sublist:
res = True
break
print("Is sublist present in list ? : " + str(res)) -7
OR
# using all()
flag = 0
if(all(x in test_list for x in sub_list)):
flag = 1
if (flag):
print("Yes, list is subset of other.")
else:
print("No, list is not subset of other.") -7
Module III
15 a) import turtle (7)
t = turtle.Turtle()
t.fillcolor("red")
t.pencolor("black")
t.begin_fill()
for count in range(6):
t.forward(length)
t.left(60)
t.end_fill()
turtle.exitonclick() -4
Page 5of 9
0300CST362052203
if __name__ == "__main__":
main() -4
Explanation of methods -3
OR
16 a) 1) __init__ method with -6 (10)
Easy frame __init__ call
Two addLabel and addFloatField method calls
Two addButton method calls
Page 6of 9
0300CST362052203
b) Attributes: -2 (4)
title (an empty string by default)
width and height in pixels
resizability (true by default)
background color (white by default)
Changing the attributes: -2
Any two out of the following three ways
1.through _init__ method
2. reset them in the window’s attribute dictionary
3. run a method included in the EasyFrame class
Module IV
17 a) Rectangle Class defenition with constructor to set height, width - 3 (7)
Two member functions to find area, and perimeter -2 + 2
b) Inheritance implementation -Explanantion+ Illustration -4 (7)
Each class below the topmost one inherits attributes and behaviors from its
ancestors and extends these with additional attributes and behavior.
class <new class name>(<existing parent class name>):
Polymorphism implementation - Explanantion+ Illustration-3
Two methods that have the same header but have different definitions in different
classes.
OR
18 a) Student class definition with constructor for receiving name and roll number. 2 (7)
Methods to :
1. Display - It should display all informations of the student. -1
2. setAge - It should assign age to student -2
3. setTestMarks - It should assign marks of a test to the student. -2
b) Exceptions Explanation and common exceptions in Python-2 (7)
Python Try Catch statement -3
Page 7of 9
0300CST362052203
Illustartion - 2
Module V
19 a) 1. arr2d[:2] = > [[1, 2, 3], (8)
[4, 5, 6]]
2. arr2d[:2, 1:] = > [[2, 3],
[5, 6]]
3. arr2d[1, :2] => [4, 5]
4. arr2d[:2, 1:] = 0 => [[1, 0, 0],
[4, 0, 0],
[7, 8, 9]] 2*4=8
b) import csv (6)
filename = "university_topper.csv"
csvwriter = csv.writer(csvfile)
csvwriter.writerow(fields)
csvwriter.writerows(rows)
OR
20 a) Import panda and read csv -2 (4)
Number of rows and columns => use shape() -1
First five rows => use head() -1
b) Import required libraries, matplotlib library for visualization and importing csv (10)
library for reading CSV data.
1. Open the file using open( ) function with ‘r’ mode (read-only) from CSV
library and read the file using csv.reader( ) function.
2. Read each line in the file using for loop.
3. Append required columns of the CSV file into lists.
Page 8of 9
0300CST362052203
4. After reading the whole CSV data, plot the required data as scatter/plot
using plt functions.
5*2 =10
****
Page 9of 9