Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Lesson 8 updated
# 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 GetName(self): print (self.first, self.last) def GetEmail(self): print (self.email) # write a method to display salary def GetSalary(self): print (self.pay) # write a method to raise the salary by some percentage def RaiseSalary(self, amt): self.pay=self.pay+(self.pay*amt/100) # write a method to display the gender def GetGender(self): print (self.gender) def SetGender(self, gender): self.gender = gender # write a method that gives the nationality of the employee def SetNationality(self, nationality): self.nationality=nationality def GetNationality(self): print(self.nationality) # Getters (Accessors) -> return/print something # Setters (Mutators) -> Setting/calculating something ''' 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() # First data structure: Stack
run
|
edit
|
history
|
help
0
Sieve of Eratosthenes
vbcb
Game3
(P3) Zadanie Kolokwium 2013: Trójkąty i trójkąty
kenken1
H.W5
Python
kawaii
Q1
LinearSearch.py