1.
Student Details Class
Create a class to store and display student information.
class Student:
def __init__(self, name, roll):
[Link] = name
[Link] = roll
def display(self):
print("Name:", [Link])
print("Roll No:", [Link])
s1 = Student("Ravi", 101)
[Link]()
Concept: class, object, constructor, attributes.
2. Rectangle Area
Find the area of a rectangle using a class.
class Rectangle:
def __init__(self, length, width):
[Link] = length
[Link] = width
def area(self):
print("Area =", [Link] * [Link])
r = Rectangle(5, 3)
[Link]()
Concept: attributes + method.
3. Circle Area
Calculate area of a circle.
class Circle:
def __init__(self, radius):
[Link] = radius
def area(self):
print("Area =", 3.14 * [Link] * [Link])
c = Circle(7)
[Link]()
4. Calculator Class
Perform basic arithmetic operations.
class Calculator:
def add(self, a, b):
print("Addition:", a + b)
def sub(self, a, b):
print("Subtraction:", a - b)
c = Calculator()
[Link](10, 5)
[Link](10, 5)
Concept: methods inside class.
5. Employee Salary
Store employee details and display salary.
class Employee:
def __init__(self, name, salary):
[Link] = name
[Link] = salary
def display(self):
print("Employee:", [Link])
print("Salary:", [Link])
e = Employee("John", 50000)
[Link]()
6. Bank Account
Deposit and check balance.
class BankAccount:
def __init__(self, balance):
[Link] = balance
def deposit(self, amount):
[Link] += amount
print("New Balance:", [Link])
b = BankAccount(1000)
[Link](500)
7. Temperature Converter
Convert Celsius to Fahrenheit.
class Temperature:
def __init__(self, celsius):
[Link] = celsius
def convert(self):
f = ([Link] * 9/5) + 32
print("Fahrenheit:", f)
t = Temperature(30)
[Link]()
8. Car Information
Store car details.
class Car:
def __init__(self, brand, model):
[Link] = brand
[Link] = model
def show(self):
print("Car:", [Link], [Link])
c1 = Car("Toyota", "Innova")
[Link]()
9. Number Checker
Check whether number is even or odd.
class Number:
def __init__(self, num):
[Link] = num
def check(self):
if [Link] % 2 == 0:
print("Even")
else:
print("Odd")
n = Number(7)
[Link]()
10. Product Price with Discount
Calculate final price.
class Product:
def __init__(self, price):
[Link] = price
def discount(self):
final = [Link] * 0.9
print("Discounted Price:", final)
p = Product(1000)
[Link]()