Exam Question Paper
Exam Question Paper
General Instructions
• Attempt all questions
• Please upload your solutions to your Microsoft Teams Folder in a SINGLE pdf file only.
Section-A
Q-1 (a) Write a function OddEven( ) that returns two separate lists each having even and
odd numbers respectively in the range of 1 to 50. (2 marks)
(b) Write a function xyz( ) that estimates roots (α, β) of quadratic equation p( x ) =
x2 − 8x + 16 = 0. Further, determine the ratio of the roots.(3 marks)
For a range of numbers x ∈ (0, 3] in steps of 0.25, determine the function value g( x ).
(5 marks)
Q-3 (a) Create a function named delph( ) that returns cube root of all the values in a se-
quence σH = {1, 9, 81, 729, −98, 67.8, 71.1, 200}. (2 marks)
(b) Luke’s weight is 138.31 pounds with a height of 175.84 cm. Determine, if his body
mass index is greater/less than an upper and lower threshold of 20.55 and 22.75.
If the BMI value violates the threshold, create an array of ones with a size of 20 x
1. Else create an array of zeros with size 40 x 1. (3 marks)
Q-4 Write a function named Bazzinga that prints the numbers from 1 to 150. But for mul-
tiples of three print “Fizz” instead of the number and for the multiples of five print
“Buzz’z”. For numbers which are multiples of both three and five print “Suit Up!”. (5
marks)
Q-5 Consider matrix H and L below and answer the questions that follow. (5 marks)
√
1 4 5 17 π/5 1 2
H= , L = −5
−5 8 9 34 1100 π 8
Section-B
Q-7 Write a program to write and read from the text file. [5]
(a) Write following sentences in the given order to a new text file. (day name.txt)
[1]
’Monday \n’
’Tuesday \n’
’Wednesday \n’
’Friday \n’
’Thursday \n’
’Saturday \n’
Page 2
(b) Open a file using ‘with’ keyword and read content of the text file (day name.txt).
[1]
(c) Write ‘Sunday \n’ at the end of the file. [1]
(d) Change the order of Friday and Thursday in day name.txt file (i.e. . . . Wednesday
\n Thursday \n Friday \n . . . ) using readlines( ) and writelines( ) methods. [2]
Q-8 Write a program to read/write .csv file and to raise multiple exceptions [5]
(a) Create a new csv text file (trig.csv) and write in it 11 number from 0 to 1 (i.e.
0, 0.1, 0.2, . . . , 0.9, 1.0) and their sine and cosine values separated by commas [2]
Sample output :
>>> Number,sin,cosine
0.0,0.0,1.0
0.1,0.099..,0.995..
: : :
***************
Best wishes
Page 3