Python term work questions mca ai ds
Q1.
An electricity company charges different rates based on units consumed.
First 100 units – 5rs/unit next 100 unit-7rs/unit above 200 units-10rs/unit
Also,if bill exceeds 2000rs add 5% surcharge.
Q2 Design a Python program to simulate an e-commerce discount engine for an online
shopping platform. The program should calculate the discount and final payable amount
based on the following rules:
1. If the total purchase amount is ₹10,000 or more, give a 20% discount.
2. If the total purchase amount is ₹5,000 or more but less than ₹10,000, give a 10%
discount.
3. If the total purchase amount is less than ₹5,000, no discount is given.
4. If the payment method is Credit Card and the original purchase amount is ₹8,000 or
more, provide an additional ₹500 cashback after discount.
The program should:
• Take purchase amount and payment method as input.
• Calculate the applicable discount and cashback.
• Display the discount amount and final payable amount after all deductions
Q3 Design a Python program to simulate ATM login. A user is allowed 3 attempts to enter
the correct PIN.
If the entered PIN matches the stored PIN → display “Access Granted”.
If the entered PIN is wrong → display “Wrong PIN” and
Q4 Write a Python simulator to model a traffic signal system for a smart city.
• The traffic signacycles through 3 lights:
o Green for 5 seconds
o Yellow for 2 seconds
o Red for 7 seconds
• This cycle repeats indefinitely.
• For a given time duration n seconds, print which light is ON at each second.
Q5 Write a Python simulator to monitor a patient’s hourly temperature in a [Link]
hospital continuously monitors a patient’s health by recording body temperature once
every hour. To ensure timely medical intervention, the system should detect cases of
sustained high fever.
• The hospital records temperature once every hour.
• If the patient’s temperature exceeds 100°F for 3 consecutive hours, the system should
trigger an alert.
• The program should:
Input the total number of hours to be monitored.
Accept hourly temperature readings from the user.
If the temperature exceeds 100°F for three consecutive hours, trigger an alert.
• The program should:
o Print the first time interval (hours) when the alert condition occurs.
o If no such condition is found, display “No alert required”.
Q6 Design a program to analyze student results. Each student is represented as a tuple:
(roll_number, name, [marks in subjects])
You are given a list of such student records. You need to:
1. Calculate the average marks for each student.
2. Assign grades based on average:
• A: 85+
• B: 70–84
• C: 50–69
• F: below 50
3. Return a list of tuples with:
(roll_number, name, average, grade)
Q7. In a university portal, students should not register for the same course twice. Use sets
to maintain
registered courses. Write a Python program that:
Takes course codes as input until the student types "done".
Stores them in a set.
Displays the final list of registered courses in order it will add.
If a student tries to register for the same course again, display: "Already registered!"
Q9You're given a 2D matrix where:
1 = Nuclear leak source (dangerous zone)
(0) Safe area
You need to mark all directly adjacent cells (top, bottom, left, right) of a 1 as unsafe by
changing them to -1.
This simulates how danger spreads from the source to nearby zones.
Q10-An IT company wants to shortlist students who know both Python and NoSQL. Write a
Python program:
Take student names for Python and NoSQL knowledge one by one.
Stop input when user enters "DONE".
Find the intersection (students in both).
Print the shortlisted names or "No students match the criteria".
q-11 A university library maintains records of books. Write a python program to:
1. Allow users to borrow books (store in a set).
2. Prevent duplicate borrowing (check using conditional statement).
3. Allow users to return books.
4. Display final borrowed books.
Q-12 A shopping cart is stored as a tuple of items (item_name, price, quantity). Write a
Python program to:
Print the cart in a readable format.
Calculate the total bill.
If any item quantity > 10, give a 5% discount on that item.
If total bill > 500, apply 10% discount.
Print final payable amount.
Q-13 We want to create a Student Report System. Each student has:
Name
Marks
The system should:
Show student details (instance method).
Count how many students are created (class method).
Give general info about students (static method).
Q14- Design and implement a Shopping Cart System using the concepts of Object-
Oriented Programming (OOP) in Python. The system should allow a customer to create a
shopping cart and perform the following
operations:
1. Customer-Specific Cart
Each cart belongs to a specific customer.
Customers can add multiple items (with name and price) to their cart. The cart should
display the list of items with their respective prices.
2. Cart Operations
Allow items to be added to the cart.
Display the items in the cart.
If the cart is empty, display an appropriate message.
3. System-Wide Tracking
Keep track of the total number of carts created using a class variable.
4. General Shopping Message
Display a common welcome message for all customers using a static method.
Q15- Write a Python program to implement single inheritance. Create a base class Person
that stores the basic attributes of a person, such as name and age. Derive a subclass
Student from Person which adds additional attributes such as roll number and marks. The
program should be able to:
Accept details of a student.
Display both personal and academic details.
Demonstrate the use of the super() function to reuse parent class methods
Q16Write a Python program to implement multiple inheritance. Create two classes:
Teacher class that stores the subject taught.
Researcher class that stores the research field.
Derive a class Professor from both Teacher and Researcher which also includes the
professor’s name. The program should:
Accept details of a professor (name, subject taught, research field).
Display complete details by accessing attributes of both parent classes.
Show how multiple inheritance helps in combining multiple roles into one class.
Q17-Write a Python program to demonstrate multilevel inheritance. Create the following
class hierarchy:
Person class that stores a person’s name.
Employee class that inherits from Person and adds employee ID.
Manager class that inherits from Employee and adds the department.
The program should:
Take input for a manager’s details.
Display the complete information (name, employee ID, department).
Show how data members are passed through multiple levels of inheritance
Q18-Write a Python program to demonstrate hierarchical inheritance. Create a base class
Vehicle that stores the brand name. Derive two subclasses:
Car class that adds the number of seats.
Bike class that adds engine capacity (cc).
The program should:
Take details of a car and a bike.
Display the complete details of both using their respective classes.
Illustrate how multiple subclasses can share the common features of a base class while
adding their own unique properties
Q19-Write a Python program to implement hybrid inheritance. Create:
A base class Person storing the name.
A Student class (derived from Person) that stores the course name.
An Employee class (also derived from Person) that stores the company name.
A WorkingStudent class (derived from both Student and Employee) that represents a
person who studies and also works.
The program should:
Accept details of a working student.
Display the combined information (name, course, company).
Demonstrate how hybrid inheritance works and how ambiguity is resolved using explicit
constructor calls.
Q20Create a program that divides two user inputs.
Handle:
• Non-numeric input (ValueError)
• Division by zero (ZeroDivisionError)
• Always print a completion message.
Q21-Write a Python program to accept marks of a student for multiple
subjects and compute the percentage.
Raise and handle:
• NegativeMarksError if any mark < 0
• MarksOutOfRangeError if any mark > 100
• InsufficientSubjectsError if the number of subjects < 3
• Display detailed error messages for each case.
Q22-Simulate a fund transfer between two accounts (balances provided
by user). Raise InsufficientFundsError if source balance is insufficient, InvalidAmountError
for non-positive transfer, and handle input errors. Print final balances on success.
Q23-A university wants to maintain daily attendance records using a
Python program. Each student ID should be stored in a text file called [Link].
Task: Write a Python program to:
• Take 10 student roll numbers as input
• Store them in a file
• Then display the stored attendance list
Q24-A company collects customer reviews and stores them in
[Link].
Task: Write a Python program to:
• Accept feedback messages from 5 customers
• Append each feedback to the file
• Count and display total feedback entries
Q25-A teacher wants to maintain a backup of student marks from [Link]
to [Link].
Task: Write a Python program to copy all content from [Link] to [Link].
Q26-Write a program that asks the user to enter an integer age and then
check that age is between 0 and 120.
If input cannot be converted to int, catch the ValueError and raise a custom
InvalidInputError
from the original ValueError.
If conversion succeeds but age is out of range, raise a custom AgeOutOfRangeError.
Print a friendly success message on valid input from exception handling
Q27-Write a Python program to input the marks of a student and validate
the entered marks using exception handling.
If the entered marks are less than 0, raise a custom exception named NegativeMarksError.
If the entered marks are greater than 100, raise another custom exception named
MarksOutOfRangeError.
If the marks are within the range 0 to 100, display the message "Valid Marks".
The program should handle these exceptions gracefully using try-except blocks and
display
appropriate error messages.
Q28-Include these programs in a file: 4. Write a Tkinter program that uses the grid layout to
create a small login form with:
• Label & Entry for Username
• Label & Entry for Password
• Login Button
On clicking Login, display a message box:
“Login Successful”
Q29-Design and implement a Python program using the Tkinter library to create a graphical
user interface (GUI) application. The application should contain a button which, when
clicked, displays a message box showing the message “Hello” and simultaneously
changes the background color of the main window.
Q30-Write a Tkinter program to design a simple calculator using Python Tkinter that
performs basic arithmetic operations (addition, subtraction, division and multiplication).
Q31-Write a Python program to copy the contents of a source file into a destination file
using file handling concepts.
Q32-Write a Python program to open a text file, read its contents, and count the total
number of words and characters present in the file. Display the counted number of words
and characters on the screen.