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

Python Programming Exam Questions 2025

For python programming
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)
6 views2 pages

Python Programming Exam Questions 2025

For python programming
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

R22A

Code No.: 22CSC40N


CHAITANYA BHARATHI INSTITUTE OF TECHNOLOGY (Autonomous)
B.E / [Link] I Sem (Main) Examination January 2025
Problem Solving and Programming using Python
(Common to Civil, Mech, ECE, EEE, EVL,Chem & Biotech)
Time: 3 Hours Max Marks: 60
Note: Answer ALL questions from Part-A at one place in the same order and Part–B
(Internal Choice)
Part - A
(5Q X 2M = 10 Marks)
M CO BT
1 What is a Python interpreter? (2) 1 1
2 Mention the use of the type() function in Python. (2) 2 1
3 Outline the operator precedence (2) 3 2
4 Summarize the benefits of using the NumPy module for arrays. (2) 4 2
5 Demonstrate the text and binary files in python. (2) 5 2-

Part - B
(5Q X 10M = 50 Marks)
M CO BT
6 (a) Write an algorithm for checking whether the given number is a Prime (5) 1 2
number or Not?
(b) What are the symbols used in flowchart and draw the flowchart for the (5) 1 2
above problem
(OR)
7 (a) Demonstrate the identifiers, keywords and literals in Python. (5) 1 2
(b) Compare script mode and interactive mode of programming in Python. (5) 1 4

8 (a) Discuss type conversion in Python with examples. (5) 2 4


(b) Compare numeric data types in Python with examples. (5) 2 4
(OR)
9 (a) Explain the purpose and usage of Python's dictionary with examples. (5) 2 2
(b) Write a Python program to demonstrate operations on sets. (5) 2 3

10 (a) Write a Python program to print the following pattern (5) 3 2


50
49 48
47 46 45
44 43 42 41
(b) Demonstrate the selection and loop control structures in Python. (5) 3 2
(OR)
11 (a) Explain logical and relational operators in python with suitable (5) 3 2
examples.
(b) Explain comprehensions in Python with an example of list (5) 3 2
comprehension.

12 (a) Compare recursion and iteration with examples. (5) 4 4


Page 1 of 2
R22A
Code No.: 22CSC40N
(b) Demonstrate the use of parameter types in Python functions with suitable (5) 4 2
examples.
(OR)
13 (a) Differentiate between function definition and function call with suitabe (5) 4 4
example.
(b) What are lambda functions in Python? Explain their usage with an (5) 4 2
example.

14 (a) Compare searching techniques (Linear vs Binary Search) with an (5) 5 3


example.
(b) What is a binary file? How is it different from a text file? (5) 5 2
(OR)
15 (a) Write a Python program to copy the contents of one file to another file. (5) 5 2
(b) Create a Python program to implement selection sort. (5) 5 4

*****

Page 2 of 2

Common questions

Powered by AI

Operator precedence in Python dictates the order in which operators are evaluated in expressions. Operators with higher precedence are evaluated before operators with lower precedence. For example, in the expression '3 + 4 * 2', the multiplication operation is performed first due to its higher precedence, resulting in '3 + 8' which evaluates to 11. Understanding operator precedence is crucial to correctly structuring complex expressions to ensure the desired outcome.

The NumPy module in Python provides a powerful array object that is more efficient than traditional Python lists for numerical operations. Benefits include faster execution of numerical computations due to optimized implementation in C, ability to perform element-wise operations efficiently, memory efficiency, and the availability of a vast number of mathematical operations and functions for arrays. Additionally, NumPy arrays support multidimensional data and broadcasting, making them ideal for complex mathematical and matrix operations.

The Python interpreter is responsible for executing Python code by translating it into machine-readable bytecode, which is then executed by the Python virtual machine. Unlike a compiler, which translates the entire program into machine code before execution, a Python interpreter translates code line-by-line at runtime. This means Python can execute dynamically typed statements and scripts, providing immediate Error Feedback if something goes wrong.

Text files in Python store data in human-readable format using a specific character encoding, such as UTF-8, while binary files store data in raw byte format, which is not human-readable. The main implication of this difference is that binary files are more efficient for storing data that is not text, such as images or executable files, as they preserve the full fidelity of the data. In contrast, text files are easier to read and manipulate for applications involving human-readable content. Furthermore, binary files require careful handling of data streams to ensure data is read or written correctly.

Script mode in Python allows users to write, save, and execute a sequence of commands from a file, enabling robust program development. This mode is beneficial for creating reusable code and debugging large programs. However, it can be less intuitive for beginners due to the absence of immediate feedback. Interactive mode, accessed via the Python shell, provides immediate execution and feedback for each command, making it ideal for experimentation, learning, and testing small code snippets. The trade-off is that interactive mode does not support saving and organizing code effectively. In educational settings, script mode encourages the development of structured code, while interactive mode aids in a rapid learning curve.

Type conversion in Python allows smooth transition and compatibility between different data types, ensuring operations across various types are executed without errors. Python provides built-in functions such as int(), float(), and str() to convert values from one type to another. For example, converting a string '123' to an integer can be done using int('123'), facilitating arithmetic operations on user inputs that initially arrive as strings. This flexibility in type conversion is crucial for ensuring data integrity and functionality in programs involving dynamic data types.

Recursion and iteration both achieve repetitive tasks in Python but differ fundamentally. Recursion involves functions calling themselves, offering a clear and concise expression for problems like tree traversal or factorial calculation. However, recursion can lead to significant memory usage due to the function call stack and may cause stack overflow for deep recursions. Iteration, utilizing loops like for or while, is more memory efficient as it doesn't involve function calls stacking, but can lead to more complex code for certain problems. Recursion provides simplicity for problems natural to recursive decomposition, while iteration is suited for straightforward repetitive processes due to its efficiency.

Logical operators in Python (and, or, not) are used to combine conditional statements, while relational operators (==, !=, >, <, >=, <=) are used to compare values. Together, they can be used effectively to implement complex decision-making logic. For example, using relational operators to compare a user's input against multiple criteria, and then combining these comparisons using logical operators to execute code blocks based on multiple conditions: `if user_age > 18 and user_permission == True:`. This combined use allows for robust conditional expressions, making programs more flexible and responsive to varied inputs.

Linear Search iterates through all elements in a list sequentially until the desired element is found, making it simple to implement but inefficient with a time complexity of O(n), especially for large datasets. In contrast, Binary Search requires the list to be sorted and employs a divide-and-conquer approach, significantly enhancing efficiency with a time complexity of O(log n). Binary Search is ideal for large, sorted datasets due to its speed, while Linear Search is suitable for unsorted data or when the dataset is small, as it doesn't require pre-sorting.

The type() function in Python is used to determine and return the type of an object. It is particularly useful in debugging to check and validate the type of variables at runtime, helping ensure functions receive and return the expected data types, which can prevent errors in type-sensitive operations. This function enhances dynamic type checking, a feature of Python, allowing programmers to handle types more flexibly.

You might also like