Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lesson8
# Object Oriented Programming ''' 1. Create a Class called Student 2. Instantiate an object of the class (create an example of the class) 3. Student(): attribute: first name attribute: last name attribute: email address Class: Student() Object: std_1, std_2, ... Constructor: def __init__(self, ...) Attributes: first, last, email, UIN Methods: __init__(self, ...), fullname() ''' # University, Chemistry Course [40 students] class Student: def __init__(self, first, last, UIN): # constructor self.first = first self.last = last self.email = first + '.' + last + '@email.com' self.UIN = UIN def fullname(self): return '{} {}'.format(self.first, self.last) # 'std_1' is an object for my class 'Student' std_1 = Student('Ali','Ahmed',100) std_2 = Student('Noor','Fatima',201) std_3 = Student('Shaikha','Ahmed',152) std_4 = Student('James','White',183) std_5 = Student('John','Hutch',104) std_6 = Student('Jim','Rogers',405) std_7 = Student('Little','Stuart',206) #print (std_1.fullname() ) ## -------------------------------------------------------------- ''' Answer the following: 1. What's the name of the class? Employee 2. What's the constructor? __init__ 3 a. How many arguments does the constructor take? 4 b. How many arguments are passed to the object of the class? 3 4. How many attributes are there? List them out. first, last, email, pay 5. Fill up the missing statements from lines 41-44 6. Create an object of the class. And run the code. emp_1 = Employee('Faiha','Maryam', 1000) 7. Who is the object for the class? emp_1 ''' class Employee: def __init__(self, first_name, last_name, salary): self.first = first_name self.last = last_name self.email = first_name + '.'+ last_name +'@email.com' self.pay = salary def disp_name(self): print (self.first, self.last) def disp_email(self): print (self.email) # write a method to display salary def disp_salary(self): print (self.pay) # write a method to raise the salary by some percentage def raise_salary(self, amt): self.pay=self.pay+(self.pay*amt/100) # write a method to display the gender def disp_gender(self): print (self.gender) def set_gender(self, gender): self.gender = gender # write a method that gives the nationality of the employee def set_nationality(self, nationality): self.nationality=nationality def disp_nationality(self): print(self.nationality) ''' Challenges 1. Print the name 2. Raise the salary 3. Include the gender of the employee ''' emp_1 = Employee('Faiha','Mariam', 10000) emp_1.set_gender('F') emp_1.set_nationality('Qatari') emp_1.disp_nationality()
run
|
edit
|
history
|
help
0
MBTI
Calculator
31 dec
try123
Юра и заселение
denemeler
HW L3
sai hw user enter table
Faiha - Lesson 8
hi