Python Coding Practice Class Method Loops || Lesson 5 || Python Placements || Learning Monkey ||

Описание к видео Python Coding Practice Class Method Loops || Lesson 5 || Python Placements || Learning Monkey ||

#python#learningmonkey#pythoncoding#placements#pythontutorials#pythoncourse#pythonforbeginners#pythonfordatascience#pythonfullcourse#pythonprogramming#pythonfreecourse

Python Coding Practice Class Method Loops
In this class, We make Python Coding Practice Class Method Loops.

These examples will help the reader to improve his coding shill.

Take our placement course and complete the practise tests to crack the campus placement exams.

After completing the placement course, the reader can attend any campus placement for service-based companies.

Please solve the examples on your own, then check for a solution.

find the output of the given code
class surgeon:
def __init__(self,surgeonid):
self.__surgeonid=surgeonid
def identifyamt(self,feelist,surgeonidlist):
amount=0.0
count=0
for index in range(len(surgeonidlist)):
if(surgeonidlist[index]==self.__surgeonid):
amt=feelist[index]
for index in range(len(surgeonidlist)):
if feelist[index]ltamt:
count+=1
return count
surgeonidlist=[1008,1004,1002,1007,1009]
feelist=[18,15,10,12,8]
surgeonobj=surgeon(1004)
print(surgeonobj.identifyamt(feelist,surgeonidlist))
In the above program, the surgeon id list and fee list are given.

The method identify amount will take the surgeon id and take the fee of that surgeon.

The second loop will count the number of surgeons having fee amounts less than the given surgeon id.

Given below is the output of the program.

Output:
3
A company is trying to conduct 2 competetions to there employees
They have opened two portals for registration
identify the code at line1 in the given class below
so that the gettotalregistration method should give total no of participants registered for both competetions
class competetion:
__count1=100
__count2=500
def __init__(self,eventname):
self.eventname=eventname
self.registrationid=None
if self.eventname=='D':
self.registrationid="DC"+str(self.count2method())
elif self.eventname=='S':
self.registrationid="SC"+str(self.count1method())
@classmethod
def count1method(cls):
cls.__count1+=1
return cls.__count1-1
@classmethod
def count2method(cls):
cls.__count2+=1
return cls.__count2-1
def gettotalregistration(self):
-line 1-
obj1=competetion('D')
obj2=competetion('S')
obj2.gettotalregistration()
In the above program, we need to identify the code in the method to get total registration.

The method, get total registration should return the total number of registrations.

We have two class methods.

To learn the basics of class and objects. Click here.

The count1 method will increase the variable count1 by one whenever registration is done on event ‘D.’

The count2 method will increase the variable count2 by one whenever registration is done on event ‘S’.

Initially, the count1 variable is given value 100, and the variable count2 is given value 500.

The variables count1 and count2 are class variables. They are global to all objects.

Whenever an object is created, the count variables are incremented according to the event registration.

To get the count of registrations for event ‘D’. We need to subtract the variable count1 by 100.

The number of registrations for Event ‘S’ will be obtained by subtracting the variable count2 by 500.

Given below is the code to be written at line1.

return ((competetion.__count2-500)+(competetion.__count1-100))

Link for playlists:
   / @learningmonkey  



Link for our website: https://learningmonkey.in

Follow us on Facebook @   / learningmonkey  

Follow us on Instagram @   / learningmonkey1  

Follow us on Twitter @   / _learningmonkey  

Mail us @ [email protected]

Комментарии

Информация по комментариям в разработке