0% found this document useful (0 votes)
31 views

IT 243 Programming With Python

Uploaded by

raman7913523
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

IT 243 Programming With Python

Uploaded by

raman7913523
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

National College of Computer Studies

Full Marks: 60
(NCCS-College of IT & Management) Pass Marks: 30
Pre-Board Examination (2024) Time: 3 Hours
Set A
BIM/Fifth Semester/ IT 243: Programming with Python
Candidates are required to answer the questions in their own words as far as practicable.
Attempt all questions.
Group ‘A’
Brief Answer Questions: [10×1=10]
1. How do you call a superclass constructor from a subclass in Python?
2. What happens if the method signature is different in the superclass and subclass during overriding?
3. How do you resolve conflicts in multiple inheritance?
4. How do you overload the greater than operator in Python?
5. How do you access the name and value of an enum member?
6. How do you handle exceptions in file handling?
7. How can we implement id() in python?
8. How do you change the text of a Tkinter Label widget dynamically?
9. How do decorators modify the behavior of a function?
10. How do you use **kwargs to pass keyword arguments to a function?

Group ‘B’
Short Answer Questions (Any Five): [5×3=15]
11. How do you use a lambda function with the map() function? Explain with examples.
12. How would you add a menu bar with "File" and "Edit" options to your Tkinter application?
13. What are the different types of inheritance in Python? Provide examples to illustrate single, multiple, and
multilevel inheritance.
14. Create a Python program to demonstrate abstraction using a base class Employee with an abstract method
calculate_salary(), and derived classes FullTimeEmployee and PartTimeEmployee that implement
calculate_salary().
15. Discuss the use of default values in constructors. Write a class Student with a constructor that initializes
name and grade with a default value of None.
16. Write a Python class Person with a method that can introduce the person with different levels of detail based
on the arguments provided.

Group ‘C’
Long Answer Questions (Any three): [3×5=15]
17. Write a python code to display:
18. Write a Python program to demonstrate the use of the finally block for resource cleanup. Use a try block to
handle file operations and ensure the file is closed using the finally block.
19. Create a Python program that iterates through a list of strings and prints each string that starts with the letter
"A".
20. Write a Python program that reads a file and counts the number of occurrences of each word in the file. The
program should then print each word alongside its count.

Group ‘D’

Comprehensive Answer Question: [2×10=20]


21. a) What is the difference between a NumPy array and a Python list? Why might you prefer using a NumPy
array in numerical computations? Create a 2x3 NumPy array of zeros and a 3x3 NumPy array of ones.
b) Write a Python script to(using sqlite3):
i. Create a database named “company.db”.
ii. Create a table named Employees with columns EmployeeID (integer, primary key), FirstName (text),
LastName (text), HireDate (text), and Salary (real).
iii. Insert a new employee into the Employees table.
iv. Retrieve and print all records from the Employees table.
22. a) How can you modify an existing element in a Python list? Can you update multiple elements at once?
Provide examples to illustrate your answer.
Given the list fruits = ["apple", "banana", "cherry", "date"], write a Python program to:
i. Replace "banana" with "blueberry".
ii. Change the last two items to "fig" and "grape".
b) What are the potential risks of using recursion? How can you avoid common pitfalls such as infinite
recursion?
Write a recursive function power(x, n) that calculates x raised to the power of n (i.e., x^n). Your
function should handle both positive and negative values of n.

******
National College of Computer Studies
Full Marks: 60
(NCCS-College of IT & Management) Pass Marks: 30
Pre-Board Examination (2024) Time: 3 Hours
Set B
BIM/Fifth Semester/ IT 243: Programming with Python
Candidates are required to answer the questions in their own words as far as practicable.
Attempt all questions.
Group ‘A’
Brief Answer Questions: [10×1=10]
1. Explain the importance of indentation in python.
2. How does method overriding affect polymorphism?
3. How do you create an abstract class with no abstract methods?
4. What is the purpose of the else block in exception handling?
5. How do you read a file line by line in Python?
6. What is the purpose of the cursor object in database operations?
7. How do you handle button click events in Tkinter?
8. What happens if you call a function with more arguments than it accepts?
9. What is the default return value of a function if no return statement is specified?
10. What is the potential issue with using mutable default arguments?

Group ‘B’
Short Answer Questions (Any Five): [5×3=15]
11. How can you achieve similar behavior to function overloading using default arguments and variable
arguments? Explain with examples.
12. Write a function that is called when a button is clicked, which changes the text of a Label to "Button
Pressed."
13. Write a Python program to demonstrate hierarchical inheritance. Create a base class Animal and derived
classes Mammal and Bird.
14. What are the benefits of using abstract classes in large software projects? Provide an example to illustrate
the advantages of abstract classes in Python. Discuss the limitations of abstract classes in Python.
15. Write a Python class Product with a constructor that initializes name, price, and quantity. Include methods
to display the product details and calculate the total price.
16. Create a Python class Shape with a method area that can calculate the area of a square, rectangle, or circle
based on the number of arguments provided.

Group ‘C’
Long Answer Questions (Any three): [3×5=15]
17. Write a python code to create the following:
18. Explain the importance of exception handling in Python. How can you define and raise custom exceptions
in Python? Write a custom exception InvalidAgeError and demonstrate its use in a program that checks for
valid age input.
19. Write a Python function that takes a list of integers as input and writes each integer to a new line in a text
file. Then, write another function that reads the integers back from the file and returns them as a list.
20. Write a Python program that reverses a string using a for loop, using slicing and using reversed() function
combined with the join().

Group ‘D’

Comprehensive Answer Question: [2×10=20]


21. a) What is the purpose of the head() and tail() functions in pandas? How do they help in exploring and
understanding large datasets? Create a DataFrame with some missing values and use the isna() function
to identify them.
a. How do you establish a connection to a MySQL database using Python? What parameters are
required? Write a Python script to(using sqlite3):
i. Write a Python program to create a new database named “nccs_db”.
ii. Create a table named students with columns id (INT), name (VARCHAR), and phone
(VARCHAR).
iii. insert 10 new records into the students table.
iv. retrieve all records from the students table and display.
22. a) Explain what list indexing and slicing are in Python. How would you access the last element of a list
using both positive and negative indexing? Provide examples.
Given the list numbers = [10, 20, 30, 40, 50, 60], write a Python program to:
i. Access and print the first element.
ii. Access and print the last element.
iii. Slice the list to get the first three elements.
iv. Slice the list to get every other element starting from the second element.
b) What is meant by "packing" and "unpacking" in the context of tuples in Python? Provide examples to
illustrate both concepts.
Write a Python function that accepts an arbitrary number of arguments using tuple packing. The function
should return the sum of all the arguments.

******

You might also like