Oops Hands - On
Oops Hands - On
Oops Hands - On
def check_balance(self):
# Method to check the current balance
print(f"Current balance: {self.balance}")
def display_info(self):
# Method to display employee information
print(f"Employee: {self.name}, ID: {self.emp_id}, Salary: {self.salary}")
def calculate_bonus(self):
# Method to calculate total salary with bonus
total_salary = self.salary + self.bonus
print(f"Total salary for Manager {self.name}: {total_salary}")
def display_info(self):
# Override the display_info method to include programming language
super().display_info()
print(f"Programming Language: {self.programming_language}")
manager.display_info()
manager.calculate_bonus()
developer.display_info()
def __str__(self):
# String representation of the product
return f"{self.name}: ${self.price}"
def calculate_total(self):
# Method to calculate the total cost
total = sum(product.price for product in self.products)
print(f"Total cost: ${total}")
cart = ShoppingCart()
cart.add_product(apple)
cart.add_product(banana)
cart.calculate_total()
cart.remove_product(apple)
cart.calculate_total()
5. Student Management System
def calculate_grade(self):
# Method to calculate grade based on marks
if self.marks >= 90:
return "A"
elif self.marks >= 75:
return "B"
elif self.marks >= 60:
return "C"
else:
return "D"
def display_info(self):
# Method to display student information
grade = self.calculate_grade()
print(f"Student: {self.name}, Roll No: {self.roll_number}, Grade: {grade}")
def display_info(self):
# Override the display_info method to include the year
super().display_info()
print(f"Year: {self.year}")
# Create objects and manage students
student1 = UndergraduateStudent("Alice", 101, 88, "2nd Year")
student2 = Student("Bob", 102, 55)
student1.display_info()
student2.display_info()
def rent_vehicle(self):
# Method to rent the vehicle
print(f"{self.brand} with ID {self.vehicle_id} rented for ${self.rental_price} per day")
def return_vehicle(self):
# Method to return the vehicle
print(f"{self.brand} with ID {self.vehicle_id} returned")
def rent_vehicle(self):
# Override the rent_vehicle method to include the number of seats
super().rent_vehicle()
print(f"This car has {self.seats} seats")
# Create objects and manage vehicle rentals
car = Car("C123", "Toyota", 50, 4)
car.rent_vehicle()
car.return_vehicle()
def __str__(self):
# String representation of the menu item
return f"{self.name}: ${self.price}"
def display_menu(self):
# Method to display the current menu
if self.menu:
print("Menu:")
for item in self.menu:
print(item)
else:
print("The menu is empty")
def __str__(self):
# Override string representation to include calories
return f"{self.name} (${self.price}) - {self.calories} calories"
def __str__(self):
# Override string representation to include size
return f"{self.name} (${self.price}) - {self.size}ml"
def __str__(self):
# Override string representation to include vegan info
vegan_str = "Vegan" if self.is_vegan else "Non-Vegan"
return f"{self.name} (${self.price}) - {vegan_str}"
# Example usage
restaurant = Restaurant()