Object Oriented Programming
✕Creating Classes
Question 1 of 4
- Attributes:
brand,model,color. Default value ofcolorshould beblue. - Methods:
display_info,start_engine,stop_engine.display_infoshould returnBrand: {brand}, Model: {model}, Color: {color}.start_engineshould return"Engine of {self.brand} {self.model} started".stop_engineshould return"Engine of {self.brand} {self.model} stopped". - Create two objects of
Carclasscar_1with brandToyota, modelCorollaand colorRed.car_2with brandHonda, modelCivic. - Call
display_info,start_engineandstop_enginefor both objects and display the output.
Create a classCarwith following details:- Attributes:
Inheritance
Question 2 of 4
- Create a class
Employeethat has: attributes:name,dob,age,salary,skill_sets. - Create class
DeveloperinheritingEmployeethat has: Additional attribute:github_link,is_fullstack. method:show_profilethat returns{name} has skills: s1, s2. Git: {git_link}. - Create class
HRinheritingEmployeethat has: Additional attribute:is_manager,onboard_rate. method:show_profilethat returns{name} has skills: s1, s2. Onboard rate: {rate}. - 5 developers and 2 HR joined the company. Create objects for them with random attribute.
- Create list
developers_listwith all developer objects and listhr_listwith all HR objects. - Loop through
developers_listto display developer's name with both Python and Git skill.
- Create a class
Method Overriding
Question 3 of 4
- Create a class called
Pointthat has: attributes:x_coordinate,y_coordinate. method:dist_from_origincalculated with formula:sqrt(x^2 + y^2). Operator:+,-that should add/substract two point with logic(x1+x2, y1+y2). method:printshould return P(x, y). Override:<,>,<=,>=,==and!=that should usedist_from_originto compare. - Create two points
p_1with coordinates(3, 4)andp_2with coordinates(1, 2). - Use
print(p_1),print(p_2)to display the points. Should giveP(3, 4)andP(1, 2). - Create a new point
p_3by addingp_1andp_2. i.ep_3 = p_1 + p_2. Displayp_3. - Calculate distance of
p_1andp_2from origin usingdist_from_originmethod. - Compare
p_1andp_2using overridden operators. i.e.p_1 > p_2,p_1 <= p_2etc.
- Create a class called
Encapsulation
Question 4 of 4
- Create a class
BankAccountthat has: attributes:owner,__balance(private attribute with default value 0). methods:deposit,withdraw,get_balance,transfer.depositto add amount to balance if it's is +ve.withdrawto subtract amount from balance if it's +ve and less than balance.get_balanceto display current balance.transferto transfer amount from one account to another. - Create two accounts
account_1with ownerRabindraandaccount_2with ownerJohn. Deposit 1000 toaccount_1and 500 toaccount_2. Withdraw 200 fromaccount_1and 100 fromaccount_2. Transfer 200 fromaccount_1toaccount_2.
- Create a class
