Sunday, May 17, 2026

Python Material - Part - 19 - Oops - 2

 __author__ = "Narendra Boyina"


# -----------------------------------------------------------------------------
# Copyright (c) 2025 BR Technologies PVT LTD
#-----------------------------------------------------------------------------
"""
Topics to be covered in today's class:
--> Docstring with example
--> pass keyword with example
--> How to use class variable inside method
"""


class Salary_hike:
"""
This class is designed to help HR to calculate year-end salary increases based on employee performance and other parameters
"""
x = 100 # class variable / attribute

def __init__(self, EmpId, Expe, sal, Level, Rating):
self.EmpID = EmpId
self.Expe = Expe
self.Level = Level
self.Rating = Rating
if(Expe == 1 and Level == "c1" and Rating == "superstar" ):
print(" Hike is 25%,Salary after increment",((.25*sal)+sal))
elif(Expe == 1 and Level == "c1" and Rating == "star" ):
print(" Hike is 20%,Salary after increment",((.20*sal)+sal))
elif(Expe == 1 and Level == "c1" and Rating == "pillor" ):
print(" Hike is 15%,Salary after increment",((.15*sal)+sal))
elif(Expe == 1 and Level == "c1" and Rating == "below expectations" ):
print(" Hike is 9%,Salary after increment",((.10*sal)+sal))

elif((Expe == (2 or 3)) and Level == "c2" and Rating == "superstar" ):
print(" Hike is 18%,Salary after increment",((.18*sal)+sal))
elif((Expe == (2 or 3)) and Level == "c2" and Rating == "star" ):
print(" Hike is 15%,Salary after increment",((.15*sal)+sal))
elif((Expe == (2 or 3)) and Level == "c2" and Rating == "pillor" ):
print(" Hike is 10%,Salary after increment",((.10*sal)+sal))
elif((Expe == (2 or 3)) and Level == "c2" and Rating == "below expectations" ):
print(" Hike is 8%,Salary after increment",((.08*sal)+sal))

elif(Expe == (4 or 5 or 6) and Level == "c3" and Rating == "superstar" ):
print(" Hike is 15%,Salary after increment",((.15*sal)+sal))
elif(Expe == (4 or 5 or 6) and Level == "c3" and Rating == "star" ):
print(" Hike is 12%,Salary after increment",((.12*sal)+sal))
elif(Expe == (4 or 5 or 6) and Level == "c3" and Rating == "pillor" ):
print(" Hike is 8%,Salary after increment",((.08*sal)+sal))
elif(Expe == (4 or 5 or 6) and Level == "c3" and Rating == "below expectations" ):
print(" Hike is 6%,Salary after increment",((.06*sal)+sal))

elif(Expe == (7 or 8 or 9) and Level == ("c4" or "c5") and Rating == "superstar" ):
print(" Hike is 13%,Salary after increment",((.13*sal)+sal))
elif(Expe == (7 or 8 or 9) and Level == ("c4" or "c5") and Rating == "star" ):
print(" Hike is 9%,Salary after increment",((.09*sal)+sal))
elif(Expe == (7 or 8 or 9) and Level == ("c4" or "c5") and Rating == "pillor" ):
print(" Hike is 7%,Salary after increment",((.07*sal)+sal))
elif(Expe == (7 or 8 or 9) and Level == ("c4" or "c5") and Rating == "below expectations" ):
print(" Hike is 5%,Salary after increment",((.05*sal)+sal))

elif(Expe >=10 and Level == ("c6" or "c7") and Rating == "superstar" ):
print(" Hike is 10%,Salary after increment",((.10*sal)+sal))
elif(Expe >=10 and Level == ("c6" or "c7") and Rating == "star" ):
print(" Hike is 7%,Salary after increment",((.07*sal)+sal))
elif(Expe >=10 and Level == ("c6" or "c7") and Rating == "pillor" ):
print(" Hike is 5%,Salary after increment",((.05*sal)+sal))
elif(Expe >=10 and Level == ("c6" or "c7") and Rating == "below expectations" ):
print(" Hike is 3%,Salary after increment",((.03*sal)+sal))

else:
print("given values are not match, please provide proper input values")


# emp_1 = Salary_hike("HM0002162", 2, 32000, "c2", "star")
# print(emp_1.EmpID)
# print(emp_1.Level)

"""
We can create multiple instances of the same class, but each instance is independent of the others.
(i.e when we have created a new instance, it will be created in a new memory location)
"""

# emp_2 = Salary_hike("HM0001669", 4, 45000, "c3", "superstar")
#
# print(emp_2.EmpID)
# print(emp_2.Level)
#
# print(id(emp_1), id(emp_2) )

"""providing wrong values"""
# emp_3 = Salary_hike("HM0001669", 4, 45000, "c1", "superstar")

"""
Docstring: It is the first string inside the class and has a brief description of the class (documentation).
Although not mandatory, this is highly recommended.
documentation string, which can be accessed via ClassName.__doc__
"""

# print(Salary_hike.__doc__)

# import keyword
# print(keyword.kwlist)

"""
--> "pass" is a keyword ( or a statement) to indicate a "null" block. &
"pass" indicate that, nothing happens inside the function/class/conditional statements/ looping statement is empty.
--> "Pass keyword, can be used to efficiently add unimplemented items quickly."
--> pass can be placed on the same line, or on a separate line. """


class Employee:
""""""
pass


class Student:

def narendra(self):
pass

def kruthika(self):
pass


class Password_verification: pass






"""How to use class variable inside method
==> by using class name (class_name.class_variable)"""

class Employee:
count = 0 # class variable /attribute (Class variables will be shared with different objects created for the same class)
year = 2019 # class variable /attribute

def abc(self): # method
Employee.count += 1 # usage of class variable inside method==> class_name.class_variable
print("Present count value: ", Employee.count)
jaya = 300

def xyz(self): # method
Employee.count += 4 # usage of class variable inside method==> class_name.class_variable
print("Present count value: ", Employee.count)

def password_verification(self):
pass

"""class_variable will be shared among all the instances created by the user"""

# s1 = Employee() # I have created instance variable / object
# print(s1.count) # outside of the class ==> instance_variable.class_variable
# print(s1.year) # outside of the class ==> instance_variable.class_variable
# Employee.year = 2025 # class variable (so it will be shared among multiple instances for the same class)
# print(Employee.year)
#
# s1.abc() # object.method
# s1.xyz()
# print(s1.count)
#
# s2 = Employee()
# print(s2.count)
# print(s2.year) # printing class variable (it will display updated value)
# s2.abc()
# print(s2.count) # class_variable (count) was shared by 2nd instance also
#
# s3 = Employee()
# s3.abc()
# print(s3.count)
# s3.year=2029
# print(s3.year)



################## practice purpose ##############
def calc_factorial(x):
"""This is a recursive function
to find the factorial of an integer"""
if x == 1:
return 1
else:
return (x * calc_factorial(x-1))

No comments:

Post a Comment