0% found this document useful (0 votes)
10 views1 page

Python Programming Exam Questions

The document outlines the semester examination for Programming in Python at Mahindra University, detailing the structure and topics covered. It includes questions on Python features, data types, loops, lists vs tuples, functions, dictionaries, and short notes on exception handling, file handling, and object-oriented programming. The total marks for the exam are 30, with a duration of 1.5 hours.

Uploaded by

jaiho738080
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)
10 views1 page

Python Programming Exam Questions

The document outlines the semester examination for Programming in Python at Mahindra University, detailing the structure and topics covered. It includes questions on Python features, data types, loops, lists vs tuples, functions, dictionaries, and short notes on exception handling, file handling, and object-oriented programming. The total marks for the exam are 30, with a duration of 1.5 hours.

Uploaded by

jaiho738080
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

Mahindra University - Department of Computer Science

and Engineering

Semester Examination - Programming in Python


Total Marks: 30 | Duration: 1.5 Hours

1. Explain the features of Python that make it a high-level, interpreted language. (3


Marks)

2. What are data types in Python? List and explain any four with examples. (3
Marks)

3. Write a Python program to check whether a number is even or odd. (3 Marks)

4. Explain different types of loops in Python. Write a program to print the Fibonacci
series up to n terms. (4 Marks)

5. What are lists and tuples? Explain the differences with examples. (3 Marks)

6. Explain the concept of functions in Python. Write a function to calculate factorial


of a number. (4 Marks)

7. What is the use of dictionaries in Python? Write a program to count the


frequency of each word in a given string. (4 Marks)

8. Write short notes on: (6 Marks)


a) Exception Handling
b) File Handling
c) Object-Oriented Programming in Python

Common questions

Powered by AI

To differentiate between even and odd numbers, Python leverages modulo operations that check the remainder of division by 2. This strategy is efficient and concise, showcasing Python’s strength in handling logical conditions with minimal code, enabling developers to implement concise and readable logic for basic arithmetic categorizations .

Python’s data types each serve distinct purposes: strings represent textual data, integers numeric, lists ordered collections, and dictionaries key-value mappings. Understanding these differences allows developers to choose the appropriate structure for data manipulation, enhancing program functionality, efficiency, and readability by leveraging each type’s unique methods and properties .

Python is classified as a high-level language due to its abstraction from machine details, allowing programmers to use natural language elements and reducing the need for deep knowledge of the hardware. Its interpreted nature means code is executed line by line, which aids in testing and debugging by providing immediate feedback. These features make Python accessible and significantly streamline the development process, enabling rapid application development and iteration .

Exception handling in Python allows developers to manage and respond to exceptions gracefully, preventing program crashes and enabling user-friendly error management. By using try-except blocks, developers can maintain program flow despite errors. However, the challenge lies in properly identifying potential exception points and crafting appropriate handling strategies, which, if neglected, can lead to obscured bugs or unmanageable code .

Dictionaries in Python store data as key-value pairs, facilitating efficient lookups, updates, and storage of associative arrays. They are ideal for managing unordered data with unique keys. For example, a word frequency counter can be implemented using dictionaries to iterate over each word in a string, updating the count stored for each word key, thereby efficiently tracking the number of occurrences for each word .

Object-oriented programming in Python is based on four core components: encapsulation, inheritance, polymorphism, and abstraction. These principles facilitate software design by promoting organized, modular code that reflects real-world structures, enhancing code maintainability, reusability, and scalability, thus allowing developers to manage complexity effectively .

Python simplifies file operations through built-in functions and context managers that automate file opening and closing, reducing boilerplate code and potential errors. Best practices include using 'with' statements for automatic resource management, validating file paths and formats, and handling exceptions to prevent data corruption during file reads and writes .

Functions enable modular programming by allowing code to be encapsulated into reusable pieces, which promotes code organization, reuse, and easier maintenance. A function to calculate the factorial of a number can be written by defining the function with an iterative or recursive approach to multiply numbers in a descending sequence from the given integer down to 1, reducing complex operations into a simple function call .

Python supports several loop structures including 'for' and 'while' loops, which allow repeated execution of a block of code. A program to print the Fibonacci series demonstrates this utility: a loop initializes the first two terms and repeatedly calculates subsequent terms by summation, updating the sequence until n terms are generated, illustrating efficient sequence generation .

Lists in Python are mutable, meaning their elements can be changed or updated, which is ideal for dynamic collections of items. Tuples are immutable, ensuring that their contents cannot be altered after creation, which offers advantages in terms of performance and ensures data integrity. This immutability of tuples can be beneficial in scenarios where a fixed data set is required, as it reduces the risk of unexpected modifications .

You might also like