0% found this document useful (0 votes)
14 views2 pages

Python Programming Exam Questions 2023

The document is a question paper for a Python Programming exam. It contains 3 parts with multiple choice and long answer questions testing concepts like operators, conditional statements, strings, files, functions, classes, exceptions, algorithms and data visualization in Python.
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)
14 views2 pages

Python Programming Exam Questions 2023

The document is a question paper for a Python Programming exam. It contains 3 parts with multiple choice and long answer questions testing concepts like operators, conditional statements, strings, files, functions, classes, exceptions, algorithms and data visualization in Python.
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

Reg. No.

Question Paper Code 12112

B.E. /[Link]. - DEGREE EXAMINATIONS, APRIL /MAY 2023


Second Semester
Information Technology
(Common to Computer Science and Engincering. Artificial Intelligence and Data
Science, Computer Science andEngincering (10T), Computer Science and Engineering
(AIML), Computer Science and Engineering (Cyber Security) &[Link]. - Computer
Science and Engineering)
20ESIT202 - PYTHON PROGRAMMING
(Regulations 2020)
Duration: 3 Hours Max. Marks: 100
PART - A(10 x2= 20 Marks)
Answer ALL Questions
Marks,
K-Level, co
1 2,K1,CO!
What is operator precedence?
2 2,KI, CO!
List the features of Python.
3 Write a C program to find whether the given number is odd or even. 2,K2,CO2

4 Write a Python program to find whether set Ais subset of set B. 2.K2,CO2

5 Comment with an example on the use of local and global variable. 2, K2,CO3
[Link],CO3
What is Aliasing? Give Example.
[Link].CO4
7. Define Errors and list its types.
8 What are classes and objects? 2,K1,CO4
2,K1.CO5
What do you mean by data visualization?
2,K1,CO
10. Name some common data structure of python's Pandas library.

PART - B (5 x 13 = 65 Marks)
Answer ALL Questions

|1. a) i) Illustrate Membership operators, ldentity operators and Logical 2A2cO


Operators.
(ii) Demonstrate a program to find Sum of n numbers Using for and 6.K2, CO!
While statement.
OR
/3K2Co
b) Explain Conditional if, alternative if, and chained conditional statements
with syntax, flowchart and example Python Programs.

12. a) What is string manipulation? Explain different functions of string 3.k2,c0


nanipulations in detail.
Al- Remember; K2 - Understand: K3 Appy: K4 -Anulyze, K5 - Evaluate, Ko -Create 12112
OR
b) txplain Lincar and binaty search with an cxlple.

a) Discuss the concept of passng the airay as an argunnent in a lunction with 3tt(u1
an exaniple program.
OR
b) Explain Packages in Python with suitable example.
14. a) llustrate in detail how text files are Read and Write in Python with 13k2 o
various COmmands.
OR
!3 K3C04
b) Write a Pthon program to handle exceptions like ZeroDivision Error.
Name Error. Type Eror. Key Error, Index Error.
7.K3COS
15. a) (i)Write a python program to plot a line graph.
6.K2 COS
(ii) Explain Array Indexing in Numpy.
OR
13 K2CO3
b) Describe various access specifiers with examples.
PART -C(1x 15 = 15 Marks)
7,K3.CO6
16. a) (i) Write aPython program to copy afilecharacter,
line by line into anew file.
word and line count in a 8K3.CO6
(i) Write a pvthon program to perform
file.
OR
b) (i) Define recursive function. Discuss with suitable example. 7,K2,CO6

(ii) Write a Python program to store 'n' numbers in a list and sort the list 8k3,CO6
using selection sort.

K5 - Evaluate: K6 -- Create 12112


K] -Remember, K2 - Understand: K3 - Appl: K4-Analyze;

Common questions

Powered by AI

Aliasing in Python occurs when two variables refer to the same object in memory. This can have serious implications in data manipulation, as modifying the object through one alias affects the other. For example: ```python list_a = [1, 2, 3] list_b = list_a # list_b is an alias for list_a list_b.append(4) print(list_a) # Outputs: [1, 2, 3, 4] ``` Both `list_a` and `list_b` refer to the same list object, so changes through one alias are reflected in the other, which can lead to unintended data changes if not carefully managed .

Error handling in Python is vital for creating robust programs that can gracefully handle unexpected events without crashing. Python uses try-except blocks to handle exceptions. A program example handling different exceptions: ```python try: a = 1 / 0 except ZeroDivisionError: print("Cannot divide by zero!") try: b = some_undefined_var except NameError: print("Variable not defined!") try: c = [1, 2, 3] print(c[4]) except IndexError: print("Index out of range!") ``` This demonstrates handling ZeroDivisionError, NameError, and IndexError effectively, ensuring the program continues to run even when these errors occur .

Recursion in Python provides a cleaner and simpler representation of problems that can be divided into identical sub-problems, such as file directories or the Fibonacci sequence. Benefits include reduced code size and better alignment with mathematical definitions. However, challenges include risk of stack overflow for deeply recursive calls and higher memory usage due to maintaining multiple stack frames. Example: ```python def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) print(factorial(5)) # Outputs: 120 ``` This example demonstrates using recursion to calculate a factorial, a natural choice for this mathematical operation but requires careful handling of base cases to prevent infinite recursion .

The Pandas library offers several data structures, the most common being the Series and DataFrame. A Series is a one-dimensional labeled array capable of holding any data type, enhancing vector operations. A DataFrame is a two-dimensional, size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns), similar to a spreadsheet or SQL table, which makes complex data manipulation and analysis tasks more efficient and intuitive .

Data visualization involves the graphical representation of data and is crucial in data science for interpreting complex datasets and uncovering patterns, trends, and correlations that might go unnoticed in raw form. It aids in better communication of results and insights to stakeholders, making data-driven decisions more accessible and understandable .

Membership operators in Python include 'in' and 'not in', which check for membership in sequences. Identity operators include 'is' and 'is not', which determine if two variables point to the same object in memory. Examples: ```python # Membership operator my_list = [1, 2, 3] print(2 in my_list) # Outputs: True print(4 not in my_list) # Outputs: True # Identity operator a = [1, 2, 3] b = a c = a[:] print(a is b) # Outputs: True, as b is the same object as a print(a is not c) # Outputs: True, as c is a copy of list a ``` These operators are crucial for checking conditions and ensuring reference validity in programs .

Reading and writing text files in Python is done using the open() function in conjunction with methods like read(), write(), and close(). A typical process includes opening a file, performing the read/write operation, and closing the file to free resources. Example of writing and reading a file: ```python # Writing to a file with open('example.txt', 'w') as file: file.write('Hello, world!') # Reading from a file with open('example.txt', 'r') as file: content = file.read() print(content) # Outputs: Hello, world! ``` Potential pitfalls include improperly closing files or not using exception handling, which can lead to resource leaks and unanticipated errors during file operations .

Conditional statements in Python control the flow of code execution based on evaluation of conditions. They include simple 'if', 'if-else', and 'if-elif-else'. Examples: - Simple 'if': ```python x = 10 if x > 5: print('x is greater than 5') ``` - 'if-else': ```python x = 3 if x > 5: print('x is greater than 5') else: print('x is not greater than 5') ``` - 'if-elif-else': ```python x = 8 if x > 10: print('x is greater than 10') elif x == 8: print('x is 8') else: print('x is less than 10') ``` Use cases vary: simple 'if' for single conditions, 'if-else' where decisions result in two outcomes, and 'if-elif-else' for multiple condition scenarios .

Operator precedence in Python determines the order in which operators are evaluated in expressions. It's important because it affects how expressions are parsed and evaluated, which can significantly alter the outcome if not properly understood. For example, in the expression '3 + 4 * 2', the multiplication has a higher precedence than addition, resulting in '3 + (4 * 2)' = 11, not '(3 + 4) * 2' = 14 .

Local variables in Python are defined within a function and can only be accessed inside that function. Global variables are defined outside of any function and can be accessed anywhere in the program. Using global variables can lead to unforeseen side effects if not carefully managed, as their values can be changed throughout the program. For example: ```python global_var = 10 def my_function(): local_var = 5 print(local_var) my_function() # Outputs: 5 print(global_var) # Outputs: 10 ``` In this example, `global_var` remains accessible outside `my_function`, whereas `local_var` does not .

You might also like