Updated 3 years ago
#### Task : 🔐
Sameer is an employee , his salary is 5000 and his job
Is to approve loan
Fill in the blanks Below : 🤔
Class : __Employee_______
Object: __Sameer_______
Property:__Salary=5000_______
Method: __approveLoan()_______
class Employee: # creating class
salary=5000 # this is a property
def approveLoan(self): # this is a method
print(' i approve loan')
sameer = Employee() # this is how we create object.
sameer.approveLoan() # here we are calling method via object
i approve loan
class Student:
def register(self):
self.school="IIT" #<-- global scope variable
gift="phone" #<-- local scope variable
def whichSchool(self):
print('i study in ',self.school)#<--global scope
print('my gift is ',gift)#<-- error coz its a local scope variable
oliver = Student()
oliver.register()
oliver.whichSchool()
i study in IIT
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-9-7d92bf43a050> in <module>
14 oliver = Student()
15 oliver.register()
---> 16 oliver.whichSchool()
<ipython-input-9-7d92bf43a050> in whichSchool(self)
8 def whichSchool(self):
9 print('i study in ',self.school)#<--global scope
---> 10 print('my gift is ',gift)
11
12
NameError: name 'gift' is not defined