cst362 Draft Scheme
cst362 Draft Scheme
0300CST362052201
1 Analysis and design provide detailed blueprints for coding a system. Without (3)
these blueprints, it may be difficult to determine whether the system will do
what it is supposed to do, and it may be difficult to minimize errors in the code
and structure it in a way that eases maintenance. (Similar explanation may
give marks)
2 i) 13 ii) 2 iii) 6 (3)
3 Cmue (3)
retupmoC
Computer
Page 1of 11
0300CST362052201
to the method call s. __ str __ () , and is simpler to write. The function call print(s)
also automatically runs str(s) to obtain the object’s string
representation for output.
8 When you inherit a child class from more than one base classes, that situation is (3)
known as Multiple Inheritance. When you inherit a class from a derived class,
then it’s called multilevel inheritance. And, it can go up any levels in Python.
9 [[0 2] (3)
[2 4]
[4 6]]
10 loc selects rows and columns with specific labels and iloc selects rows and columns (3)
at specific(implicit) integer positions . - 1 mark
Example – 2 marks
PART B
Answer one full question from each module, each carries 14 marks.
Module I
11 a) import math (7)
n = int(input('Enter the value of n :'))
x = float(input('Enter the degree :'))
d=x
x = math.radians(x)
s=1
t=1
i=1
for i in range(1,n):
t = ((-t * x * x)/((2*i)*(2 * i - 1)))
s=s+t
print ('cos(',d,') = %0.2f' % s)
b) x = int(input("Enter the value of x: ")) (7)
y = int(input("Enter the value of y: "))
product = 1
for count in range(y):
product = product * x
print(product, end = " ")
Page 2of 11
0300CST362052201
print("\n")
print("product = ", product )
OR
12 a) n = int(input(“Entter the value of n : “) (7)
for i in range(1,n+1):
for j in range(1, i+1):
print(chr(64+j),end=" ")
print()
b) print ('Enter the range :') (7)
a = int(input('Enter the lower range :'))
b = int(input('Enter the upper range :'))
for i in range(a,b+1):
prime = True
j=2
while (j <= i/2):
if (i % j == 0):
prime = False
break
j=j+1
if (prime):
print (i, end = ' ')
Module II
13 a) a. data.split() (6)
b. data.upper()
c. data.index("rules")
d. data.replace("!", "?")
4 * 1.5 = 6 marks
b) count = 0 (8)
inputFile = open("myfile.txt", 'r')
for line in inputFile:
wordlist = line.split()
for word in wordlist:
if len(word) == 4:
count += 1
print("There are", count, "four-letter words.")
OR
14 a) f = open(“numbers.txt”, 'r') (10)
Page 3of 11
0300CST362052201
numbers = []
for line in f:
words = line.split()
for word in words:
numbers.append(float(word))
Module III
15 a) from turtle import Turtle (5)
def square(t, length):
#Draws a square with the given length.
for count in range(4):
t.forward(length)
t.left(90)
b) def blackAndWhite(image): (9)
"""Converts the argument image to black and white."""
blackPixel = (0, 0, 0)
whitePixel = (255, 255, 255)
for y in range(image.getHeight()):
for x in range(image.getWidth()):
(r, g, b) = image.getPixel(x, y)
average = (r + g + b) / 3
if average < 128:
Page 4of 11
0300CST362052201
image.setPixel(x, y, blackPixel)
else:
image.setPixel(x, y, whitePixel)
main()
OR
16 a) def hexagon(t, length): (5)
#Draws a hexagon with the given length.
for count in range(6):
t.forward(length)
t.left(60)
b) def shrink(image, factor): (9)
"""Builds and returns a new image which is smaller
copy of the argument image, by the factor argument."""
width = image.getWidth()
height = image.getHeight()
new = Image(width // factor, height // factor)
oldY = 0
newY = 0
while oldY < height - factor:
oldX = 0
newX = 0
while oldX < width - factor:
oldP = image.getPixel(oldX, oldY)
new.setPixel(newX, newY, oldP)
Page 5of 11
0300CST362052201
oldX += factor
newX += 1
oldY += factor
newY += 1
return new
main()
Module IV
17 a) from math import sqrt (9)
class Complex:
def __init__(self, real, imag):
self.re = real
self.im = imag
def __str__(self):
Page 6of 11
0300CST362052201
if self.im == 0:
return '%.2f' % self.re
if self.re == 0:
return '%.2fi' % self.im
if self.im < 0:
return '%.2f - %.2fi' % (self.re, -self.im)
else:
return '%.2f + %.2fi' % (self.re, self.im)
comp1 = Complex(2, 2)
comp2 = Complex(5, 3)
solve(comp1, comp2)
b) Multiple inheritance – Explanation – 2 marks (5)
Example : 3 marks
OR
18 a) class Rational(object): (9)
"""Represents a rational number."""
def numerator(self):
"""Returns the numerator."""
return self._numer
Page 7of 11
0300CST362052201
def denominator(self):
"""Returns the denominator."""
return self._denom
def __str__(self):
"""Returns the string representation of the number."""
return str(self._numer) + "/" + str(self._denom)
def _reduce(self):
"""Helper to reduce the number to lowest terms."""
divisor = self._gcd(self._numer, self._denom)
self._numer = self._numer // divisor
self._denom = self._denom // divisor
Page 8of 11
0300CST362052201
Page 9of 11
0300CST362052201
OR
20 a) import csv (4)
# field names
fields = ['Name', 'Branch', 'Year', 'CGPA']
import csv
# data rows of csv file
rows = [ ['Nikhil', 'CSE', '2', '9.0'],
['Sanchit', 'CSE', '2', '9.1'],
['Aditya', 'IT', '2', '9.3'],
['Sagar', 'IT', '1', '9.5'] ]
filename = "student.csv"
Page 10of 11
0300CST362052201
[5 * 2 = 10 marks]
****
Page 11of 11