Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

O PREV NEXT Python3 Topics > Due Soon > Due within 1 week > 03/10/2018 06 > Exer

ID: 3725640 • Letter: O

Question

O PREV NEXT Python3 Topics > Due Soon > Due within 1 week > 03/10/2018 06 > Exercise 51245 x Workbench WORK AREA Write the definition of a class ContestResult containing: . An instance variable winner of type String, initialized to the empty String. . An instance variable second_place of type String, initialized to the empty String. . An instance variable third place of type String, initialized to the empty String. . A method called set winner that has one parameter, whose value it assigns to the instance variable winner. . A method called set second place that has one parameter, whose value it assigns to the instance variable second place. . A method called set third place that has one parameter, whose value it assigns to the instance variable third place. . A method called get winner that has no párameters and that returns the value of the instance variable winner . A method called get second place that has no parameters and that returns the value of the instance variable second place. . A method called get_third_ place that has no parameters and that returns the value of the instance variable third place. No constructor need be defined. X 5 of 5: SUBMIT

Explanation / Answer

This assignment is the python3 folder, So i have used python3 to write the code.

Pyhton3 Code:

## Start of class defination.
class ContestResult:
  
## Initilaizer.
def __init__(self):
self.__winner = ""   
self.__second_place = ""
self.__third_place = ""
  
## Setter Methods.
def set_winner(self, winner):
print("Winner is updated")
self.__winner = winner
  
def set_second_place(self, second_place):
print("Second place is updated")
self.__second_place = second_place
  
  
def set_third_place(self, third_place):
print("Third place is updated")
self.__third_place = third_place
  
## Getter methods
def get_winner(self):
print("Winner is", self.__winner)
return self.__winner
  
def get_second_place(self):
print("Second place is", self.__second_place)
return self.__second_place
  
def get_third_place(self):
print("Third place", self.__third_place)
return self.__third_place
  
##End of class defination.

result = ContestResult()
result.set_winner("Rohit")
result.set_second_place("Vicky")
result.set_third_place("Rahul")

result.get_winner()
result.get_second_place()
result.get_third_place()

Output Shown after running this program:

Winner is updated
Second place is updated
Third place is updated
Winner is Rohit
Second place is Vicky
Third place Rahul
  

Please share your feedback and concern.