Python program
Python program
Basic Programs
11. Reverse a List – Reverse elements of a list without using the built-in function.
12. Find Largest and Smallest in a List – Find max and min values.
13. Sorting a List – Implement Bubble Sort or Selection Sort.
14. String Reversal – Reverse a string using slicing and loops.
15. Count Vowels and Consonants in a String
File Handling
21. Read and Write to a File – Open a file, write some data, and read it.
22. Count the Number of Lines, Words, and Characters in a File
23. Copy the Contents of One File to Another
24. Find and Replace a Word in a File
Data Structures (Lists, Tuples, Dictionaries, Sets)
30. Class and Object Example – Create a class and object with attributes and methods.
31. Bank Account Class – Implement deposit and withdraw functions.
32. Inheritance Example – Create a base class and derived class.
33. Method Overloading and Overriding
34. Operator Overloading Example
Miscellaneous Programs
✅ Explanation: This is a simple program to print text using the print() function.
✅ Explanation: The program takes two inputs from the user, converts them to integers, adds
them, and prints the result.
✅ Explanation: The max() function finds the largest among three numbers.
2. Control Structures
2.1 Factorial of a Number
python
CopyEdit
num = int(input("Enter a number: "))
fact = 1
for i in range(1, num + 1):
fact *= i
print("Factorial:", fact)
4. String Operations
4.1 Reverse a String
text = input("Enter a string: ")
print("Reversed:", text[::-1])
✅ Explanation: Counts vowels and subtracts from total length for consonants.
6. File Handling
6.1 Read & Write to a File
with open("test.txt", "w") as f:
f.write("Hello, Python!")
✅ Explanation: Opens a file in write mode (w) and then reads it.
6.2 Count Words in a File
lst = [1, 2, 3, 4, 5]
print("Reversed List:", lst[::-1])
class Student:
def __init__(self, name, age):
self.name = name
self.age = age
def display(self):
print("Name:", self.name, "Age:", self.age)
s1 = Student("John", 20)
s1.display()
def get_balance(self):
return self.balance
acc = BankAccount()
acc.deposit(1000)
acc.withdraw(500)
print("Balance:", acc.get_balance())
9. Miscellaneous Programs
9.1 Convert Decimal to Binary
n = 5
for i in range(1, n + 1):
print(" " * (n - i) + "* " * i)