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

CST445 Python Exam Question Paper

This document is an examination paper for the course 'Python for Engineers' at APJ Abdul Kalam Technological University, intended for seventh semester B.Tech students. It consists of two parts: Part A includes 10 short answer questions, and Part B contains 8 detailed questions from five modules, covering various Python programming concepts and applications. The exam is designed to assess students' understanding and practical skills in Python, with a total duration of 3 hours and a maximum score of 100 marks.

Uploaded by

xavierbenjhonson
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)
147 views3 pages

CST445 Python Exam Question Paper

This document is an examination paper for the course 'Python for Engineers' at APJ Abdul Kalam Technological University, intended for seventh semester B.Tech students. It consists of two parts: Part A includes 10 short answer questions, and Part B contains 8 detailed questions from five modules, covering various Python programming concepts and applications. The exam is designed to assess students' understanding and practical skills in Python, with a total duration of 3 hours and a maximum score of 100 marks.

Uploaded by

xavierbenjhonson
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

C 1000CST445122205 Pages: 3

Reg No.:_______________ Name:__________________________


APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY
Seventh Semester [Link] Degree Examination December 2022 (2019 scheme)

Course Code: CST445


Course Name: PYTHON FOR ENGINEERS
Max. Marks: 100 Duration: 3 Hours

PART A
Answer all questions, each carries 3 marks. Marks

1 Define keyword and enumerate some of the keywords in Python. (3)


2 Explain flow of execution of while loop with example. (3)
3 Write a python code to search a string in the given list. (3)
4 Explain lambda functions in Python with an example (3)
5 Explain constructor in python class with example (3)
6 Write a Python class named ‘Rectangle’ constructed by a length and width and a (3)
method which will compute the area of a rectangle.
7 Write the specific purpose of functions used in plotting: (3)
i) plot( ) ii) legend( ) iii. title( )
8 Describe various modes of opening a file ? Explain any two in detail (3)
9 Generate a 1-D array of 10 random integers. Each integer should be a number (3)
between 30 and 40 (inclusive)
10 Write a python program to convert a list of numeric values into a one-dimensional (3)
NumPy array.
PART B
Answer any one full question from each module, each carries 14 marks.
Module I
11 a) Explain in detail about break statement in python with proper example. (6)
b) What is type conversion? Explain in detail with examples. (8)
OR
12 a) Write Python program to solve the quadratic equation ax2 + bx + c = 0 by getting (7)
input for coefficients from the user.
b) Explain about conditional and alternative execution statements in Python with (7)
example?

Page 1of 3
1000CST445122205

Module II
13 a) Explain the following list methods with an example. a) append( ) b) extend( ) (6)
c) insert( ) d) index( ) e) sort( ) f) reverse( )
b) Check if the items in the list are sorted in ascending or descending order and print (8)
suitable messages accordingly. Otherwise, print “Items in list are not sorted”
OR
14 a) Explain with an example, the use of functions and how functions are defined (7)
and called in Python.
b) Write a Python program to combine two dictionary adding values for common (7)
keys. d1 = {'a':10, 'b': 20, 'c':30} d2 = {'a': 30, 'b': 20, 'd':40}
Sample output: {'a': 40, 'b': 40, 'd': 40, 'c': 30}
Module III
15 a) Create a class Student with attributes name and roll no. and a method dataprint() (7)
for displaying the same. Create two instances of the class and call the method for
each instance.
b) Explain inheritance and different forms of inheritance. (7)
How they are implemented in Python ?
OR
16 a) What is polymorphism? Why do we need polymorphism? Give an example in the (7)
context of OOP in Python.
b) How to handle an exception using try except block? Explain with the help of a (7)
program.
Module IV
17 a) Create an array in the range 1 to 20 with values 1.25 apart. Another array (7)
contains the log values of the elements in the first array. Create a plot of first vs
second array. Specify the x-axis(containing first array’s values) title as ‘Random
Values’ and y-axis title as ‘Logarithm Values’.
b) Explain how matplotlib can be used to create histogram. (7)
OR
18 a) What are the two types of files? Explain different file operations (7)
b) Write a python program to count the number of words in a text file (7)

Page 2of 3
1000CST445122205

Module V
19 a) Write python program to solve the following system of equations (6)
4x1 + 3x2 - 5x3 = 2
-2x1 - 4x2 + 5x3 = 5
8x1 + 8x2 = -3
b) Illustrate how numpy arrays are created with examples. How indexing, (8)
arithmetic operations and slicing is done with examples.
OR
20 a) There exist a CSV file [Link] with following columns ( rollno, name, place, (7)
mark ) of n students. Write commands to do the following using pandas library.
a) Read and display the content of [Link] file
b) Display the top l0 rows
c) Display the bottom 5 rows
d) Display Column Names and their type .
e) Find the maximum mark
f) Display Name of Columns
g) Remove the column titled place.
b) What is a pandas DataFrame? What are the different ways a DataFrame can be (7)
created in Pandas?
****

Page 3of 3

Common questions

Powered by AI

To create a histogram using matplotlib in Python, follow these steps: import the 'pyplot' module from 'matplotlib', prepare the data, and use the 'hist()' function of 'pyplot'. The 'hist()' function requires the data to be passed as an argument, and additional parameters such as 'bins' can be configured to specify the number of bins. For instance: ``` import matplotlib.pyplot as plt data = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5] plt.hist(data, bins=5) plt.xlabel('Value') plt.ylabel('Frequency') plt.title('Histogram of Data') plt.show() ``` This code will create and display a histogram of the data with 5 bins .

Numpy arrays provide several advantages over traditional Python lists for numerical computations. First, they offer enhanced performance; operations over NumPy arrays are executed in C, allowing for faster code execution. Second, they provide better memory efficiency due to their homogeneous nature, storing items of the same data type. Third, NumPy arrays support element-wise operations, advanced slicing, and indexing, enabling complex mathematical operations to be performed with concise syntax. For instance, multiplying each element in an array by 2 is straightforward with NumPy: `array * 2`. Additionally, many scientific computing libraries, such as SciPy, are designed to work efficiently with NumPy arrays, further enhancing their utility .

Inheritance in Python allows one class (the child class) to inherit the attributes and methods of another class (the parent class), enabling code reuse and the creation of hierarchical class structures. Python supports multiple forms of inheritance: single inheritance (a child class inherits from one parent class), multiple inheritance (a child class inherits from more than one parent class), multilevel inheritance (a chain of inheritance where a class is derived from a class which is also derived from another class), and hierarchical inheritance (multiple child classes inherit from a single parent class). These are implemented using class definitions in Python, where a class is defined with another class as its base: `class Child(Parent):` .

Python provides several list methods for element manipulation. 'append()' adds a single element to the end of a list, altering the list in place. 'extend()' takes an iterable argument and appends each of its elements to the list, thus extending it. 'insert()' requires two arguments: an index and an element to insert at that specific index. These methods differ in their scope and flexibility: while 'append()' is used for single additions, 'extend()' is suitable for concatenating multiple elements, and 'insert()' provides control over the exact insertion point within the list, which may affect list performance for large datasets due to element shifting .

Numpy allows arithmetic operations to be applied element-wise across arrays, facilitating efficient computations. For example, consider creating two numpy arrays and performing addition: ``` import numpy as np array1 = np.array([1, 2, 3]) array2 = np.array([4, 5, 6]) result = array1 + array2 print(result) # Output: [5 7 9] ``` Each corresponding element of 'array1' and 'array2' is added together to produce 'result', demonstrating the straightforward syntax for vectorized operations in numpy .

File modes in Python specify the operations permitted on a file when it is opened. The read ('r') mode allows reading of a file's contents; it is the default mode when a file is opened and does not permit writing to the file. The write ('w') mode allows writing to a file and creates the file if it does not exist. If the file exists, 'w' mode truncates the file, erasing its content before writing new data. For example, opening a file in write mode: `with open('file.txt', 'w') as file: file.write('Hello, World!')`, writes 'Hello, World!' to 'file.txt', discarding any existing content .

Lambda functions are often used in Python for operations within lists, such as sorting, filtering, or mapping. For instance, to sort a list of tuples by the second element in each tuple, a lambda function can be used with 'sorted': ``` list_of_tuples = [(1, 3), (2, 2), (3, 1)] sorted_list = sorted(list_of_tuples, key=lambda x: x[1]) print(sorted_list) # Output: [(3, 1), (2, 2), (1, 3)] ``` The lambda function lambda x: x[1] specifies that the second element of each tuple x should be used for sorting .

The 'try except' block in Python is used to handle exceptions or runtime errors. The 'try' block contains code that might raise an exception, while the 'except' block contains code that executes if an exception occurs. This structure allows a program to continue running even when an error is encountered, preventing crashes. An example is: ``` try: division = 10 / 0 except ZeroDivisionError: print("Cannot divide by zero") ``` Here, if a ZeroDivisionError occurs, the except block is executed, printing "Cannot divide by zero" instead of terminating the program .

Python supports several forms of inheritance, which include: single inheritance, where a derived class inherits from only one base class; multiple inheritance, where a derived class can inherit from multiple base classes, leading to more complex class hierarchies; multilevel inheritance, where a derived class is a subclass of another derived class, creating a parent-child-grandchild relationship; and hierarchical inheritance, where one base class is inherited by multiple derived classes. These forms allow flexible class designs but also introduce potential complexities, such as the diamond problem in multiple inheritance, which can be managed using Python’s Method Resolution Order (MRO) and the super() function to control the inheritance chain .

Lambda functions in Python are used to create small, anonymous functions at runtime. They are defined using the lambda keyword, have no name, and can have any number of arguments but only one expression. The expression is evaluated and returned. Lambda functions are commonly used for situations where a simple function is needed for a short period, typically as an argument to higher-order functions (functions that take other functions as arguments). For example, in sorting a list of tuples based on the second element, a lambda function can be used: sorted(list_of_tuples, key=lambda x: x[1]).

You might also like