2023 June CST362-C
2023 June CST362-C
PART A
Answer all questions, each carries 3 marks. Marks
1 Jack says that he will not bother with analysis and design but proceed directly to (3)
coding his programs. Why is that not a good idea?
2 Write the output of the following python statements : (3)
i) round(12.57) ii) 5//2 iii) int(6.5)
3 Write the output of following python code : (3)
S = “Computer”
print(S[::2])
print(S[::-1])
print(S[:])
4 Write a recursive function in python to find GCD of two numbers. (3)
5 Illustrate the function of following methods in turtle (3)
i) turtle.setheading(0) ii)turtle.forward(50) iii) turtle.left(90)
6 Describe two fundamental differences between terminal-based user interfaces (3)
and GUIs.
7 Explain what the __ str __ method does and why it is a useful method to include (3)
in a class.
8 Compare multiple and multilevel inheritance (3)
9 Write the output of the following python code: (3)
import numpy as np
arr1 = np.arange(6).reshape((3, 2))
arr2 = np.arange(6).reshape((3,2))
arr3 = arr1 + arr2[0].reshape((1, 2))
print(arr3)
Page 1of 4
0300CST362052201
10 What is the difference between loc and iloc in pandas DataFrame. Give a suitable (3)
example.
PART B
Answer one full question from each module, each carries 14 marks.
Module I
11 a) Write a python program to find the sum of the cosine series 1 - x^2/2! + x^4/4!- (7)
.......
b) Write a python program to find X^Y or pow(X,Y) without using standard (7)
function
OR
12 a) Write a python program to generate the following type of pattern for the given N (7)
rows where N <= 26.
A
AB
ABCD
ABCDE
b) Write a python program to generate prime numbers within a certain range (7)
Module II
13 a) Assume that the variable data refers to the string "Python rules!". Use a string (6)
method to perform the following tasks:
a. Obtain a list of the words in the string.
b. Convert the string to uppercase.
c. Locate the position of the string "rules" .
d. Replace the exclamation point with a question mark.
b) Write a code segment that opens a file for input and prints the number of four- (8)
letter words in the file
OR
14 a) Assume that there is a text file named “numbers.txt”. Write a python program to (10)
find the median of list of numbers in the file without using standard function for
median.
b) Use higher order python function filter to extract a list of positive numbers from (4)
a given list of numbers. You should use a lambda to create the auxiliary function.
Page 2of 4
0300CST362052201
Module III
15 a) Write a python function to draw a square using turtle graphics (5)
b) Write a python function to covert an image to black and white using image (9)
processing methods.
OR
16 a) Write a python function to draw an hexagon using turle graphics (5)
b) Write a python function to shrink an image by a given factor. The function suppose (9)
to builds and returns a new image which is smaller copy of the argument image,
by the factor argument.
Module IV
17 a) Write Python program to create a class called as Complex to model complex (9)
numbers and implement _add__( ) and __mul__() methods to add and multiply
two complex numbers. Display the result by overloading the + and * operator.
b) Explain multiple inheritance in Python with a suitable example (5)
OR
18 a) Write a Python program to create a class called as Rational to model rational (9)
numbers and associated operations. Implement the following methods in the class.
Use operator overloading.
1. Reduce() – to return the simplified fraction form
2. __add__() - to add two ratioanal numbers
3. __lt__() - to compare two rational numbers (less than operation)
b) What is Exception handling? Write a program that opens a file and writes "Hello (5)
Good moring" to it. Handle exceptions that can be generated during I/O operations
Module V
19 a) Write a code segment that prints the names of all of the items in the current (5)
working directory.
b) Write a python program to create two numpy arrays of random integers between (9)
0 and 20 of shape (3, 3) and perform matrix addition, multiplication and transpose
of the product matrix.
OR
20 a) Write Python program to write the data given below to a CSV file named (4)
student.csv
fields = ['Name', 'Branch', 'Year', 'CGPA']
Page 3of 4
0300CST362052201
Page 4of 4