Pyhton Exp2
Pyhton Exp2
Factorial of number :-
def factorial(n):
return 1 if(n == 1 or n == 0) else n * factorial(n-1)
num = 5
print("Factorial of", num, "is", factorial(num))
Output :
if select == 1:
print(num_1, "+", num_2, "=", add(num_1, num_2))
if select == 2:
print(num_1, "-", num_2, "=", sub(num_1, num_2))
if select == 3:
print(num_1, "*", num_2, "=", mul(num_1, num_2))
if select == 4:
print(num_1, "/", num_2, "=", divide(num_1, num_2))
Output :
3. Updating and Displaying Employee Details :-
class Employee:
def __init__(self, name, emp_id, salary, department):
self.name = name
self.id = emp_id
self.salary = salary
self.department = department
def calculate_salary(self, hours_worked):
overtime = 0
if hours_worked > 50:
overtime = hours_worked - 50
self.salary = self.salary + (overtime * (self.salary / 50))
def assign_department(self, emp_department):
self.department = emp_department
def print_employee_details(self):
print("Name: ", self.name)
print("ID: ", self.id)
print("Salary: ", self.salary)
print("Department: ", self.department)
print()
employee1.assign_department("OPERATIONS")
employee4.assign_department("SALES")
employee2.calculate_salary(52)
employee4.calculate_salary(60)