Struggling with program

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Feb 18 05:25:06 EST 2013


----- Original Message -----
> I'm trying to do this assignment and it not working, I don't
> understand why...
> 
> This is what I have to do:
> 
> 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 .
>  No constructor need be defined.
> Here is my code:
> 
> class Player:
> 
> 	
> 	name = ''
> 	
> 	def __init__(self,score = 0)
> 	
> 	def set_name (self):
> 		self.name
> 
> 	def set_score (self):
> 		self.score
> 
> 	def get_name
> 		return name
> 	
> 	def  get_score
> 		return score
> 
> can someone please help me?

class Player:

  # here are class attributes
  foo = 'I am a class attribute'

  # now the methods
  def __init__(self):
    # instance attributes
    self.name = ''
    self.score = 0

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

  def get_name(self):
    return self.name
  

I hope you'll be able to figure how to write the score related methods.

Cheers,

JM


-- IMPORTANT NOTICE: 

The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.


More information about the Python-list mailing list