Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39061

Re: Struggling with program

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'string.': 0.04; 'modify': 0.05; 'constructor': 0.07; 'parameter': 0.07; 'python': 0.09; '(self):': 0.09; 'defined.': 0.09; 'variables,': 0.09; 'zero.': 0.09; 'def': 0.10; 'slightly': 0.15; 'assigns': 0.16; 'attribute,': 0.16; 'attribute?': 0.16; 'attributes.': 0.16; 'colon.': 0.16; 'parameter,': 0.16; 'parameters,': 0.16; 'subject:program': 0.16; 'two).': 0.16; 'string': 0.17; 'wrote:': 0.17; 'instance': 0.17; '(or': 0.18; 'variable': 0.20; 'define': 0.20; 'parameters': 0.20; 'trying': 0.21; 'error.': 0.21; '2.x': 0.22; '3.x': 0.22; 'assignment': 0.22; 'assuming': 0.22; 'body,': 0.22; 'defined': 0.22; 'class.': 0.23; 'for?': 0.23; 'player': 0.23; 'references': 0.23; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'rules': 0.27; 'object,': 0.27; "doesn't": 0.28; 'run': 0.28; 'post': 0.28; 'initialized': 0.29; 'name?': 0.29; 'question:': 0.29; 'definition': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; "i'm": 0.29; 'error': 0.30; 'at:': 0.31; 'point': 0.31; 'url:python': 0.32; 'int': 0.33; 'to:addr:python-list': 0.33; 'code:': 0.33; 'me?': 0.33; 'tutorial': 0.33; 'another': 0.33; 'version': 0.34; 'so,': 0.35; 'pm,': 0.35; 'sometimes': 0.35; 'next': 0.35; 'but': 0.36; 'url:org': 0.36; 'method': 0.36; 'subject:with': 0.36; 'data': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'url:docs': 0.38; 'page': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'called': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'help': 0.40; 'first': 0.61; 'different': 0.63; 'here': 0.65; 'subject: ': 0.66; 'received:74.208': 0.71; 'score': 0.75; '2.7.': 0.84; 'received:74.208.4.194': 0.84; 'working,': 0.84; 'do:': 0.91; 'url:tutorial': 0.93
Date Sun, 17 Feb 2013 21:49:32 -0500
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: Struggling with program
References <5d90a61d-f122-4dd4-8d79-c9909662b2bc@googlegroups.com>
In-Reply-To <5d90a61d-f122-4dd4-8d79-c9909662b2bc@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:D+HgTodNi0v9T3DqE2AadSEKiU9wcfEv2IZvDzUeaVZ fFlRJGiJGbeFOr1DIAJnply/wlPqSpjhR76z00cYHs8+4w+MRI W3/96lozLl8QlnoS2pO+Y9UXuCCz30TDM+y9/nIHl6lnx108Ce 0+6mOWCMDU8AsFf4pnOS5V2205id1RPI/6jnfxRo3FisKUjbYY S9VCzXylPXBNWGdpmeJi5A8ieUMNj/JqbQV987B7n2VhGNRgYk eMOvSt8K/0HmsMfipKzSY4wGo87nGtJlWCCJf931TKVvP8tR4r b9yWKpUDQY+iMteFJy2hvmUs8pMKiAhLh5B01wCA04eQA9nvA= =
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1919.1361155785.2939.python-list@python.org> (permalink)
Lines 80
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1361155785 news.xs4all.nl 6873 [2001:888:2000:d::a6]:49531
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:39061

Show key headers only | View raw


On 02/17/2013 09:29 PM, maiden129 wrote:

First question:  What version of Python are you writing this for? 
Version 2.x has slightly different rules than version 3.x


> I'm trying to do this assignment and it not working, I don't understand why...
>

Define "working."  Do you mean you get a syntax error when you try to 
run it?  If so, then post the full traceback, which will point to the 
location of the error, (or sometimes the next line or two).

> 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:

If this is Python 2.x, then you want to derive from object, not just 
make a standalone class.

>
> 	
> 	name = ''

Have you read the Python tutorial page at:
      http://docs.python.org/2/tutorial/classes.html
That's assuming you're writing for Python 2.7.

python doesn't have instance variables, they're called instance data 
attributes.  Have you defined name as an instance attribute, or a class 
attribute?


> 	
> 	def __init__(self,score = 0)

Without a colon, this is a syntax error.
And without a body, it's another syntax error.
> 	
> 	def set_name (self):

Where is the parameter to hold the new name?

> 		self.name

This references the instance attribute, but doesn't modify it.
>
> 	def set_score (self):
> 		self.score
>
> 	def get_name
>

No parens, no parameters, no colon.

		return name
> 	
> 	def  get_score

ditto

> 		return score
>
> can someone please help me?
>


-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Struggling  with program maiden129 <sengokubasarafever@gmail.com> - 2013-02-17 18:29 -0800
  Re: Struggling  with program Dave Angel <davea@davea.name> - 2013-02-17 21:49 -0500
  Re: Struggling  with program Michael Torrie <torriem@gmail.com> - 2013-02-17 20:49 -0700
  Re: Struggling with program Chris Angelico <rosuav@gmail.com> - 2013-02-18 17:49 +1100

csiph-web