0% found this document useful (0 votes)
17 views3 pages

Exam Question Paper

The document outlines instructions and questions for a midterm exam on Python programming. It provides general instructions, then lists multiple choice and coding questions across two sections covering different course syllabi. The questions involve writing functions to perform tasks like analyzing quadratic equations, creating matrices, working with files, and raising exceptions.

Uploaded by

p19209425
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views3 pages

Exam Question Paper

The document outlines instructions and questions for a midterm exam on Python programming. It provides general instructions, then lists multiple choice and coding questions across two sections covering different course syllabi. The questions involve writing functions to perform tasks like analyzing quadratic equations, creating matrices, working with files, and raising exceptions.

Uploaded by

p19209425
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Adani Institute of Infrastructure Engineering

Department of Electrical Engineering


Python Programming (3151108)
Mid Term, Date: Sep 5, 2020

Timing: 12:00 to 1:45 PM Spring 2020-21, Semester V Max mark: 40

General Instructions
• Attempt all questions

• Section-A consists of questions from Dr. Dhiman’s syllabus.

• Section-B consists questions from Dr. Jadav’s syllabus.

• Please upload your solutions to your Microsoft Teams Folder in a SINGLE pdf file only.

• Filename should be firstname mse.pdf. For e.g. pratham mse.pdf.

• Assume suitable data if necessary.

• Plagiarism in solutions will lead to a penalty of 50% of question weightage.

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)

Q-2 Consider the following piecewise function



 1 if 0 < x ≤ 1
g( x ) = 2.7 if 1 < x ≤ 2
−0.8 otherwise

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

(a) Determine the number of elements in H.


(b) Determine the size of matrix L using appropriate command
(c) Perform matrix slicing by removing last column of H.
(d) Consider matrix G= 21 HT H, create a matrix Q = 2G + 14 L

Q-6 Create a module named Minkowski that has following functions


∂f √
(a) a function named linearize that estimates ∂x for f ( x, y) = x2 y3 − 7.5y2 x and
returns its value at x = 1, y = −1. (3 marks)
(b) a function named forza that returns the number of odd multiples of 7 between 1 to
100. (2 marks)

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..
: : :

(b) Read (trig.csv) file using for loops [1]


(c) Write a program that accepts integer number from the user and check whether
given number is positive or not. If number is negative, raise an exception that
number is negative. Also, raise an exception if number is zero. [2]

***************
Best wishes

Page 3

You might also like