Re: Need help improving number guessing game

2008-12-17 Thread Arnaud Delobelle
"D'Arcy J.M. Cain" writes: > On Tue, 16 Dec 2008 13:59:24 -0800 > Scott David Daniels wrote: >>> > def yesno(s): >> >s = s.strip().lower() >> >if not s in ("y", "n"): There was a thread about "is not" recently. Python also allows "not in". if s not in ("y", "n"): > You could

Re: Need help improving number guessing game

2008-12-16 Thread r . drew . davis
On Dec 15, 1:29 pm, feba wrote: > 6; can anyone think of anything else to add on to/do with this game? > With the minr/maxr display, multiplayer, score keeping, and > automation, I'm just about all of ideas. All I can think of left to > add is 3 and 4 player modes, or a fork where player 2 can't

Re: Need help improving number guessing game

2008-12-16 Thread D'Arcy J.M. Cain
On Tue, 16 Dec 2008 13:59:24 -0800 Scott David Daniels wrote: >> > def yesno(s): > >s = s.strip().lower() > >if not s in ("y", "n"): You could also do this to be a little more user friendly: if not (s and s[0] in ("y", "n")): Or reverse the test for clarity. -- D'Arcy J.M. Cain

Re: Need help improving number guessing game

2008-12-16 Thread Scott David Daniels
Bruno Desthuilliers wrote: The generic version of your above code could be: def safeinput(prompt, convert): while True: x = input(prompt) try: x = convert(x) except ValueError, e: print("Bad input : %s" % e) else:

Re: Need help improving number guessing game

2008-12-16 Thread feba
>The good news is that Python functions are objects too, so you can pass >them as params to another function. duh, duh, duh, duh, duh! I knew I was missing something there. Thanks. >if not mini <= x <= maxi: also thanks for this, I forgot about that. But I have it as if not minr < guess < maxr:

Re: Need help improving number guessing game

2008-12-16 Thread Bruno Desthuilliers
feba a écrit : .strip() returns a copy of the string without leading and ending whitespaces (inlcuding newlines, tabs etc). Ahh. I had removed it because it didn't seem to do anything, but I've readded it. And I understand your dictionary stuff correctly now, I think, and I worked it in. Curre

Re: Need help improving number guessing game

2008-12-15 Thread feba
> .strip() returns a copy of the string without leading and ending whitespaces (inlcuding newlines, tabs etc). Ahh. I had removed it because it didn't seem to do anything, but I've readded it. And I understand your dictionary stuff correctly now, I think, and I worked it in. Currently, I have:

Re: Need help improving number guessing game

2008-12-15 Thread Bruno Desthuilliers
feba a écrit : Alright! This is feeling more like it. #!/usr/bin/python #Py3k, UTF-8 import random (snip) def youwin(game): if game['pnum'] == 1: print("CONGRATULATIONS! IT TOOK YOU %s GUESSES" % game ['gcount']) else: if game['player'] == game['player1']:

Re: Need help improving number guessing game

2008-12-15 Thread feba
Spent a bit more time looking over suggestions and working out some annoyances. import random def customrange(game, lowunsafe=True): game['defrang'] = False #Keeps setup from changing range to defaults while lowunsafe: #makes sure that the low number is positive picklow = int(inp

Re: Need help improving number guessing game

2008-12-15 Thread feba
I added the ability to select your own range. It takes two new modules: def customrange(game, lowunsafe=True): game['defrang'] = False #Keeps setup from changing range to defaults while lowunsafe: #makes sure that the low number is positive picklow = int(input("PLEASE PICK THE LOW

Re: Need help improving number guessing game

2008-12-15 Thread feba
Alright! This is feeling more like it. #!/usr/bin/python #Py3k, UTF-8 import random def setup(game, minr=1, maxr=99): #minr, maxr make minimum and maximum. Can be adjusted. game['minr'], game['maxr'] = minr, maxr game['gcount'] = 0 #Reset guess count game['target'] = random.randin

Re: Need help improving number guessing game

2008-12-15 Thread Steven D'Aprano
On Mon, 15 Dec 2008 01:06:51 -0800, feba wrote: > I don't really understand dicts yet; actually, the tutorial I'm > following (http://www.briggs.net.nz/log/writing/snake-wrangling-for- > kids/ , designed for tweens, but other than the pointless anecdote > and joke here and there, I've found it a v

Re: Need help improving number guessing game

2008-12-15 Thread James Stroud
feba wrote: I don't see the aim of your changes to setup(). I can kinda understand checking to make sure that you didn't make the minimum higher than the maximum, but I think where you put minr/maxr would make it use the same minr/maxr as the end of the previous game, wouldn't it? No. Each fun

Re: Need help improving number guessing game

2008-12-15 Thread feba
>Seems ok. You may want to use arguments with default values for a and b >(and possibly to use more meaningfull names): I changed it to minr and maxr. Mini is fine, but I can't name a variable maxi unless I have a good feminine hygiene joke to use with it. I don't see the aim of your changes to s

Re: Need help improving number guessing game

2008-12-14 Thread James Stroud
It looks much better. But as Bruno suggests and as I alluded to earlier, you should get in the habit of forming verification loops on input channels that aren't already guaranteed to provide valid input messages. I'm not sure how to say that in English, but in python my example was: while True

Re: Need help improving number guessing game

2008-12-14 Thread Bruno Desthuilliers
feba a écrit : #!/usr/bin/python #Py3k, UTF-8 import random def setup(): #global target, guess, a, b #a, b make minimum, maximum. Can be adjusted. a, b = 1, 99 target = random.randint(a, b) return a, b, target Seems ok. You may want to use arguments with default values for

Re: Need help improving number guessing game

2008-12-14 Thread Bruno Desthuilliers
feba a écrit : #!/usr/bin/python #Py3k, UTF-8 import random def startup(): print("WELCOME TO THE SUPER NUMBER GUESSING GAME!") global pnum, play, player, p1sc, p2sc You should now try to rewrite the whole thing to avoid using globals. pnum = int(input("1 OR 2 PLAYERS?\n> ")) W

Re: Need help improving number guessing game

2008-12-14 Thread feba
#!/usr/bin/python #Py3k, UTF-8 import random def setup(): #global target, guess, a, b #a, b make minimum, maximum. Can be adjusted. a, b = 1, 99 target = random.randint(a, b) return a, b, target def playerswitch(player): #Player Switch #if player's a witch, burn her!

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
James Stroud wrote: Be assured that it takes on special intelligence to write unintelligible I meant "*no* special intelligence". -- http://mail.python.org/mailman/listinfo/python-list

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
feba wrote: This is what I have so far. better? worse? Much better. I didn't check if it works. But you need to figure out a way to give up on your reliance on global variables. They will end up stifling you in the long run when you move to substantial projects. Also, you should start movin

Re: Need help improving number guessing game

2008-12-13 Thread feba
#!/usr/bin/python #Py3k, UTF-8 import random def startup(): print("WELCOME TO THE SUPER NUMBER GUESSING GAME!") global pnum, play, player, p1sc, p2sc pnum = int(input("1 OR 2 PLAYERS?\n> ")) play = True player = "P1" #P1 goes first p1sc = 0 #Number of times... p2sc = 0

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
I forgot to return target: def guess(player, p1score, p2score): target = None guess1 = int(input("\n>> ")) if guess1 > 100: print("ONLY NUMBERS FROM 1 TO 99") elif guess1 > target: print("TOO HIGH") elif guess1 == target: print("GOOD JOB, PLAYER %s! THE SCORE IS:" % player)

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
James Stroud wrote: 1. Refactor. You should look at your code and see where you repeat the same or similar patterns, see where they differ, make functions, and make the differences parameters to the function call: def guess(player, p1score, p2score): guess1 = int(input("\n>> ")) if guess1

Re: Need help improving number guessing game

2008-12-13 Thread Steven D'Aprano
On Sat, 13 Dec 2008 00:57:12 -0800, feba wrote: > I have one major problem with this; the 'replay' selection. It quits if > you put in 0, as it should, and continues if you put in any other > number. However, if you just press enter, it exits with an error. it > also looks really ugly, and I'm sur

Re: Need help improving number guessing game

2008-12-13 Thread James Stroud
feba wrote: #!/usr/bin/python/ #Py3k, UTF-8 import random print(" --- WELCOME TO THE SUPER NUMBER GUESSING GAME --- " + ("\n" * 5)) pnum = int(input("1 OR 2 PLAYER?\nP#: ")) target = random.randint(1, 99) #Pick a random number under two digits guess1 = 0 #Zero will never be picked as target..

Need help improving number guessing game

2008-12-13 Thread feba
#!/usr/bin/python/ #Py3k, UTF-8 import random print(" --- WELCOME TO THE SUPER NUMBER GUESSING GAME --- " + ("\n" * 5)) pnum = int(input("1 OR 2 PLAYER?\nP#: ")) target = random.randint(1, 99) #Pick a random number under two digits guess1 = 0 #Zero will never be picked as target... guess2 = 0 #