0% found this document useful (0 votes)
13 views4 pages

Pyhton Exp2

The document contains Python code snippets for three functionalities: calculating the factorial of a number, performing basic arithmetic operations (addition, subtraction, multiplication, division) on two numbers, and managing employee details including salary calculations and department assignments. Each section includes function definitions and examples of how to use them. The employee management section demonstrates updating and displaying employee information after performing operations like salary calculation and department reassignment.

Uploaded by

ankurkumar99421
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Pyhton Exp2

The document contains Python code snippets for three functionalities: calculating the factorial of a number, performing basic arithmetic operations (addition, subtraction, multiplication, division) on two numbers, and managing employee details including salary calculations and department assignments. Each section includes function definitions and examples of how to use them. The employee management section demonstrates updating and displaying employee information after performing operations like salary calculation and department reassignment.

Uploaded by

ankurkumar99421
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

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 :

2. Addition, Subtraction, Multiplication or Division of 2 numbers :-


def add(num1, num2):
return num1 + num2
def sub(num1, num2):
return num1 - num2
def mul(num1, num2):
return num1 * num2
def divide(num1, num2):
return num1 / num2

print("Please select operation \n"


"1. Addition \n"
"2. Subtraction \n"
"3. Multiplication \n"
"4. Division \n")

select = int(input("Select operation from 1,2,3,4: "))


num_1 = int(input("Enter number 1: "))
num_2 = int(input("Enter number 2: "))

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 = Employee("ADAMS", "E7876", 50000, "ACCOUNTING")


employee2 = Employee("JONES", "E7499", 45000, "RESEARCH")
employee3 = Employee("MARTIN", "E7900", 50000, "SALES")
employee4 = Employee("SMITH", "E7698", 55000, "OPERATIONS")

print("Original Employee Details:")


employee1.print_employee_details()
employee2.print_employee_details()
employee3.print_employee_details()
employee4.print_employee_details()

employee1.assign_department("OPERATIONS")
employee4.assign_department("SALES")

employee2.calculate_salary(52)
employee4.calculate_salary(60)

print("Updated Employee Details:")


employee1.print_employee_details()
employee2.print_employee_details()
employee3.print_employee_details()
employee4.print_employee_details()
Output :

You might also like