Answer to Question #87979 in Python for Lynci Brown

Question #87979
Write the definition of a class Player containing:
An instance variable name of type String, initialized to the empty String.
An instance variable score of type int, initialized to zero.
A method called set_name that has one parameter, whose value it assigns to the instance variable name.
A method called set_score that has one parameter, whose value it assigns to the instance variable score.
A method called get_name that has no parameters and that returns the value of the instance variable name.
A method called get_score that has no parameters and that returns the value of the instance variable score.
1
Expert's answer
2019-04-15T13:15:45-0400
class Player:

  def __init__(self):
    self.name = ""
    self.score = 0

  def set_name(self, new_name):
    self.name = new_name

  def set_score(self, new_score):
    self.score = new_score

  def get_name(self):
    return self.name
   
  def get_score(self):
    return self.score

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS