"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
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
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
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:
>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:
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
> .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:
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']:
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
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
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
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
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
>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
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
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
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
#!/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!
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
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
#!/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
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)
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
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
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..
#!/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 #
26 matches
Mail list logo