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

OOP Exam Questions for Python

Uploaded by

avni38802
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)
12 views3 pages

OOP Exam Questions for Python

Uploaded by

avni38802
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

SIKKIM MANIPAL UNIVERSITY

IlISEMESTER [Link](AI& DS)DEGREE EXAMINATION


OBJECTORIENTED PROG. USING PYTHON
AD 1303 |CGPA -(21)(3CR)I
Duration: 3hrs Max marks: 100

Note: Answer all questions.


Any missing or misprinted data may be assumed suitably. 8
[Link] Sub Marks
Description
[Link]. allotted
1 (a) Formulate arithmetic operations (Addition, Subtraction, Multiplication, and [7]
Division) on integers. Input the two integer values and operatOr 1or
performing arithmetic operation through keyboard.
(b) Construct apython program to find whether the given number is odd or even. [5]
(c) Write a python program to print the factorial of a given number. [5]
(d) What recursive function? 3]
2 (a) Express multilevel inheritane with
v an example. [7]
(b) Construct a program to demonstrate parameterized constructor. [5]
(c) Make a comparison between object-oriented and procedure-oriented [S]
programming languages.
(d) Explain your understand ing about command line arguments. [3)
3 (a) Explain life cycle of a thread with proper diagram. [7]
(b) Develop a simple program which illustrates exceptions handling. [5]
(C) Demonstrate inheritance in python with example. [5]
(d) Difference between built in exceptions and handling exception. [3]
4 (a) Develop a program to display all the lines in a file [Link]" which have [7]
the word to" in it.
(b) What are the different operations we can perform on file?
(c) Create a program to demonstrate try, finally block with syntax.
(d) [5]
In how many different ways multithreading can be achieve in python?
[3]
5 (a) Develop a program to write the string Welcome! Please have a seat" in the
file [Link], that has not yet been created.
(b) Write a short note on packaging python projects. [5]
(c) Create a Python GUI program to create three single line text-box to accept a
value from the user using tkinter module.
(d) What is an Exception?
[3]

Page 1 of 1
SIKKIM MANIIPAL UNIVERSITY
EXAMINATION
IISEMESTER [Link](AI& DS) DEGREE
USING PYTIION
OBJECT ORIENTED PROG.
AD 1303 |CGPA-(21) (3CR)]
Max nrks: 100
Duration: 3hrs
13 JAN 2023
Note: Answer all questions. suitably.
Any missing or misprinteddata may beassumed
Description Marks
[Link] Sub allotted
[Link]. using
1 (a) Write a pythonprogram for swapping of two numbers with and without |71
temporary variable.
Write apython program to Iind the given year is leap or not. [5]
(b) Explain the break and continuc statement with the help of "for loop" witlh an [5]
(c)
example.
Differentiate global and local variables. |3|
(d)
List different types of inheritance and explain cach onc with suitable examples.
2 (a) Write a program 1o demonstrate parameterizedconstructor in the basc class
(b)
and derived class.

(c) Define class? How to create a class and its object in python. |I44]
(d) Describe user-defined function in pytlhon. |3]

3 (a) Demonstrate about the GUI programming in python with proper program 17]
example.
(b) What is the predefined function uscd to find length of a string? Illustrate with [2+3|
a suitable program.
(c) Differentiate between method overloading and method overriding.
(d) What do you understand by errors and exception? [3]
4 (a) Express multilevel inheritance with an example. [7]
(b) Write a program to read .txt file using for loop". [5]
(c) Differentiate between file modes rt and wt with respect to python. [5]
(d) What is recursive function? (31
(a) Creat a program to execute thrcad synchronization mechanism in python.
(b) Execute a python GUI program to create two buttons: exit and hello using
tkinter module.
(c) Write five benefits of multithreading in python. [S]
(d) Write a short note on PyPI. [3]

1/1
SIKKIM MANIPAL UNIVERSITY
SEMESTER [Link](AL& DSs) DEGREE EXAMINATION
OBJECT ORIENTED PROG. USING PYT'ION
Duration: 3hrs AD 1303 |CGPA -(21) (3CR)]
Max marks: 100
Note: Answer all
Any missing or questions.
misprinted data may be assumed suitably.
[Link] Sub
[Link]. Description Marks
(a) allotted
What are the major features and
1o find applications
(b) Create recursive function of python?
(c) factorial of a number.
Develop a single program to show publicprivate
(d) What is protected access modilier.
2
Indentation? Explain with example. |1+2|
(a)
(b)
Explain inheritance in python with
(c)
Write about class constructor ( init example.
0)and
17]
(d) Differentiate betwcen method overloading sclf-variable.
and method overriding.
Describe polymorphism.
3 |3]
(a) List out different string
three. operations. Writc an example program ior any |l+6]
(b) Make a comparison between
default constructor and
(c)
constructor. paramctcrised
Explain thread life cycle using propcr
(d) What is root window? diagram. [5]
4 |3]
(a) Create a user defined exception with an
(b) Create a python program to read a given example
CSV file
program.
(c) Develop a python program to read first 'n' lines ofasa [Link].
(d) Why Exception Handling is required?
5 [3]
(a) Construct a program to execute thread synchronization mechanism in
python.
(b) Write a python GUI program to add a
tkinter module. button in your application using
(c) Write a python program to create a table and
table. insert some records in that [5]
(d) Write a short note on python package index
(PyPI). [3]

Fage 1 of 1

Common questions

Powered by AI

Multilevel inheritance in Python refers to a situation where a class is derived from another class, which is also derived from another class. This creates a chain of inheritance. For example, consider class A as the base class, class B as derived from A, and class C derived from B. This structure allows class C to inherit features from both class B and class A. This concept can be implemented in Python through class definitions and is useful for creating a hierarchical class structure .

Exception handling in Python is crucial for managing errors and ensuring a program can handle unexpected situations without crashing. It is implemented using 'try' and 'finally' blocks where the 'try' block lets you test a block of code for errors, and the 'finally' block lets you execute code regardless of the result of the try block. This ensures that the program can handle exceptions gracefully and execute necessary cleanup operations. For instance, file handling operations can benefit from this as the 'finally' block can ensure that files are properly closed after operations .

Command-line file operations in Python are employed to manage and manipulate files directly from the terminal or command prompt using Python scripts. This can include reading, writing, or modifying file contents using built-in functions in Python such as 'open()', 'read()', and 'write()'. These operations are essential for tasks that automate data processing and file management scenarios. They are useful in creating scripts that batch process files, automate backups, or parse and analyze data sets from files .

Built-in exceptions in Python are the standard exceptions defined by Python, such as ZeroDivisionError, FileNotFoundError, and TypeError, which address common error scenarios pre-defined by the language. User-defined exceptions allow programmers to create tailored exceptions specific to their application's needs. They are created by defining a new class that derives from a standard base exception class like 'Exception'. For example, a custom exception class 'InvalidInputError' can be defined for handling specific input validation errors that are not covered by built-in exceptions .

Multithreading in Python can significantly enhance performance by enabling the concurrent execution of multiple parts of a program, particularly beneficial for tasks involving IO-bound processes. Benefits include improved application responsiveness, better CPU utilization, simplified design for programs requiring multitasking, the ability to manage simultaneous operations like concurrent file or network access, and reduced computation time for parallelizable tasks. However, due to Python's Global Interpreter Lock (GIL), true parallel execution is limited, but it suits IO-heavy applications well .

Command line arguments in Python are inputs that are passed to a program at the time of execution from the terminal. They allow a user to input parameters directly from a command line interface. In Python, the 'sys' module provides a way to handle these inputs through 'sys.argv', which stores the command line inputs as a list. By using command line arguments, programs can be made more dynamic and user-friendly, allowing for different modes of operation based on user-provided inputs .

Object-oriented programming (OOP) languages emphasize objects and encapsulation, where data and functions are bundled into entities called objects, facilitating concepts like inheritance and polymorphism. This allows for modular and reusable code design. Procedure-oriented programming (POP) languages focus on procedures or functions, where execution is typically a sequence of statements. OOP supports complex data structures and promotes code reusability, while POP is often simpler and more intuitive for small or straightforward tasks. The choice between these paradigms depends on the application's complexity and requirements .

In Python, method overloading is not natively supported as it is in some other languages, since Python functions are variables that can be reassigned at runtime. However, method overloading can be mimicked through default arguments or variable-length argument lists. Method overriding, on the other hand, is a feature that allows a child class to provide a specific implementation of a method that is already defined in its parent class, enabling polymorphism. This allows for dynamic method resolution and can change the behavior of inherited methods .

The lifecycle of a thread in Python consists of several states: New, Runnable, Running, and Terminated. Once a thread object is created, it enters the 'New' state. By calling the 'start()' method, it transitions to the 'Runnable' state. From 'Runnable', the thread scheduler moves it to the 'Running' state when it gets CPU time. Finally, once the thread has completed execution, it moves to the 'Terminated' state. Proper visualization with a diagram helps in understanding how threads transition between these states during their lifecycle, ensuring efficient thread management .

Thread synchronization in Python is a mechanism to ensure that two or more threads do not simultaneously execute critical sections of a program, preventing race conditions. It can be implemented using various synchronization primitives like Locks, Semaphores, and Events from the 'threading' module. A Lock, for instance, can be used to ensure that only one thread executes a specific critical section at a time. Proper synchronization ensures data integrity and consistency when multiple threads operate on shared resources .

You might also like