Re: [Tutor] Need a solution.

2009-06-15 Thread Alan Gauld
"spir" wrote Actually, it seems that only in the scientific field values are everywhere top-level things. Values _are_ the kind of things maths manipulate. Right? Thats an interesting observation that had not occured to me but I think you are right. What is interesting to me is that when

Re: [Tutor] Need a solution.

2009-06-15 Thread spir
Le Sat, 13 Jun 2009 13:55:58 +0100, "Alan Gauld" s'exprima ainsi: > I think that you have a valid point but that "pure value" objects > occur far less often than you might think. I always treat a value > object as a sign that I've probably put some processing code > in the wrong place! Only wh

Re: [Tutor] Need a solution.

2009-06-13 Thread ALAN GAULD
> Ok, I think I am getting somewhere now :) A lot better, now add the comparison methods: > class GuessedNumber: > def __init__(self, count=0, attempts=None): > self.attempts = attempts > self.number = randrange(1,99) > self.count = count > def step(self): >

Re: [Tutor] Need a solution.

2009-06-13 Thread David
Alan Gauld wrote: "David" wrote class GuessError(Exception): pass class GuessedNumber: def __init__(self,tries=None,limits=None):... def generate(self, limits=None):... def __cmp__(self, aNumber): if self.count >= self.tries: raise GuessError Thanks always for the feedback

Re: [Tutor] Need a solution.

2009-06-13 Thread Alan Gauld
"spir" wrote Any time you have a class that just has an __init__ it means its not doing anything. And that's a bad sign. Classes are there to *do* things not just store data. We can use a tuple or dictionary to do that. While this is probably true for _single_ objects in most case, I guess

Re: [Tutor] Need a solution.

2009-06-13 Thread spir
Le Sat, 13 Jun 2009 09:20:36 +0100, "Alan Gauld" s'exprima ainsi: > Any time you have a class that just has an __init__ it means > its not doing anything. And that's a bad sign. Classes are there > to *do* things not just store data. We can use a tuple or > dictionary to do that. While this i

Re: [Tutor] Need a solution.

2009-06-13 Thread Alan Gauld
"David" wrote class GuessError(Exception): pass class GuessedNumber: def __init__(self,tries=None,limits=None):... def generate(self, limits=None):... def __cmp__(self, aNumber): if self.count >= self.tries: raise GuessError Thanks always for the feedback, i came up with t

Re: [Tutor] Need a solution.

2009-06-12 Thread David
Alan Gauld wrote: This is a bad choice of class. It is a verb which is indicative that its not an object. Objects are nearly always nouns. You could use GuessableNumber. Then it would have a number attribute which is the number to guess. It could have a generate() ,method which produces a new

Re: [Tutor] Need a solution.

2009-06-12 Thread Alan Gauld
"David" wrote have been attempting to learn about classes, this is my version, comments, suggestions always welcome. -david #!/usr/bin/python from random import randrange from sys import exit class GuessNumber: def __init__(self): self.number = randrange(100)+1 self.coun

Re: [Tutor] Need a solution.

2009-06-11 Thread David
Randy Trahan wrote: Well that didin't work I tried the program and it went into an infinite loop...is that the problem you were asking about? On Fri, Jun 12, 2009 at 12:14 AM, Randy Trahan > wrote: Hi Raj, The only thing I see is that under #guessi

Re: [Tutor] Need a solution.

2009-06-11 Thread David
Raj Medhekar wrote: I have been having some difficulty modifying this program to where a player has limited number of guesses and if he fails to guess correctly within that number he is asked to "Try Again" The original program code and the code that I modified are given below. Thanks for your

Re: [Tutor] Need a Solution!

2009-06-11 Thread Alan Gauld
"Raj Medhekar" wrote #guessing loop while guess != the_number and tries <5: Well done you correctly spotted that you could use a boolean expression. if guess > the_number: print "Lower..." else: print "Higher..." guess = int(raw_input("Take a guess:")) tries +=

Re: [Tutor] Need a Solution!

2009-06-11 Thread ayyaz
Raj Medhekar wrote: This email contains another modified code that I tried working with but still doesn't do the job right, although performs closer to what i want. I have been having some difficulty modifying this program to where a player has limited number of guesses and if he fails to guess

Re: [Tutor] Need a Solution!

2009-06-11 Thread Wayne
On Thu, Jun 11, 2009 at 1:59 PM, Raj Medhekar wrote: > This email contains another modified code that I tried working with but > still doesn't do the job right, although performs closer to what i want. I > have been having some difficulty modifying this program to where a player > has limited numb

Re: [Tutor] Need a Solution!

2009-06-11 Thread Raj Medhekar
This email contains another modified code that I tried working with but still doesn't do the job right, although performs closer to what i want. I have been having some difficulty modifying this program to where a player has limited number of guesses and if he fails to guess correctly within that

[Tutor] Need a solution.

2009-06-11 Thread Raj Medhekar
I have been having some difficulty modifying this program to where a player has limited number of guesses and if he fails to guess correctly within that number he is asked to "Try Again" The original program code and the code that I modified are given below. Thanks for your help. Sincerely, Raj