Python Programming - Assignment 3
Questions:
1. Write a Python program to create a text file named '[Link]' and write 5 student
names into it.
2. Write a program to read and display the contents of '[Link]'.
3. Write a program that appends 3 more student names to '[Link]'.
4. Write a program that counts the total number of lines in '[Link]'.
5. Write a program to handle the error when trying to read a file that does not exist.
6. Write a program that asks the user to enter a number and handles the error if the user
enters text instead.
7. Write a program to divide two numbers entered by the user and handle the error if the
denominator is zero.
8. Write a program that asks the user to input a filename. Handle the error if the file cannot
be opened.
9. Define a class called 'Book' with attributes title and author. Create an object and display
its details.
10. Add a method in the 'Book' class that displays a message like 'The book title is XYZ by
Author ABC'.
11. Create a class 'Student' with attributes name and age. Write a method to display student
details.
12. Write a program where the 'Student' class constructor (__init__) takes name and age as
arguments and initializes them.
13. Create a class 'Calculator' with methods add, subtract, multiply, and divide. Demonstrate
its usage.
14. Create a class 'Teacher' that inherits from 'Person' class and adds subject as a new
attribute.
15. Write a program to demonstrate method overriding. (Example: a parent class Animal
with method sound(), and a child class Dog that overrides sound()).
16. Write a program to read a file and handle any error that might occur during reading (e.g.,
FileNotFoundError, PermissionError).
17. Create a class 'Library' with methods to add books, remove books, and display all books.
Handle the error if a user tries to remove a book not in the library.
18. Write a program that takes user input for numbers and stores them in a file. Then read
the file and display the sum of the numbers.
19. Write a program that writes 10 random numbers into a file and then finds the largest
number from the file.
20. Create a class 'Employee' with attributes name and salary. Write a method to give a
bonus and update the salary.
21. Write a program to handle multiple exceptions (e.g., ZeroDivisionError, ValueError) in a
single block.
22. Create a class 'Course' with attributes course_name and duration. Write a method to
display the details.
23. Write a program that counts the number of words in a given text file.