Re: [Tutor] I need advice about which way to go.

2005-08-03 Thread Alan G
Hi Nathan,

The problem with this problem descripton is that you have an idea
clear in your own head but the rest oif us only have the words.
So...

 I am writing a poker game and a blackjack game.

Two separate games or one game that can play both?

 I was wondering which way would be Python smart and work properly.

That depends on you really, there is no Python way to write card games
(unless you count using PyGame but even thats not mandatory). This is
really a matter of design and Python doesn't impose many limits on 
that,
there are lots of valid approaches you could take.

 I am trying to figure out whether or not to use t(n) as a card 
 indicator,
 when n = randomly drawn number.

t(n) means a function called t that takes a parameter called n. I'm
not sure how you would use that as a card indicator. Are you confusing
functions and lists? Do you mean t[n] where n is an index into a list
called t? Then if t held all the card values (or names) n could 
indicate
one particular card. That might work.

Another way could be a dictionary with a coded name per card as the 
key
along with the value. (Aces pose a problem regardless of solution 
because
they have two values)

 I could go that way, or code it as t1, t2, t3, etc.

Having 52 variables, one per card could work but seems clumsy.
Also figuring out how to deal a hand would be tricky with discreet 
variables.

 Which way is the right and correct way to go?

There is no single right way, but a collection of some sort sounds
better than a set of independant variables.

 Also for blackjack, I want to use it as playertotal = playertotal + 
 n,
 and computertotal = computertotal + n. or 1,2,3, etc. Which is 
 better?

I don't understand that bit at all?! What does 'n'represent?
What are the 1,2,3 for?

Alan G. 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need advice about which way to go.

2005-08-03 Thread Nathan Pinno
Sorry about that, I thought it was clear that n = number randomly chosen. I 
was thinking of if the number was a five, it would choose a card with a five 
on it. I don't want to have to code stuff that I have to repeat again and 
again.
I'm not worrying about card types, I have that figured out separately.
The two games are indeed separate, too much trouble to do them a 1 program 
that can play both games.
Maybe I should have shown my code and asked using the code as a visual 
reference.
- Original Message - 
From: Alan G [EMAIL PROTECTED]
To: Nathan Pinno [EMAIL PROTECTED]; Tutor mailing list 
tutor@python.org
Sent: Wednesday, August 03, 2005 1:14 AM
Subject: Re: [Tutor] I need advice about which way to go.


 Hi Nathan,

 The problem with this problem descripton is that you have an idea
 clear in your own head but the rest oif us only have the words.
 So...

 I am writing a poker game and a blackjack game.

 Two separate games or one game that can play both?

 I was wondering which way would be Python smart and work properly.

 That depends on you really, there is no Python way to write card games
 (unless you count using PyGame but even thats not mandatory). This is
 really a matter of design and Python doesn't impose many limits on that,
 there are lots of valid approaches you could take.

 I am trying to figure out whether or not to use t(n) as a card indicator,
 when n = randomly drawn number.

 t(n) means a function called t that takes a parameter called n. I'm
 not sure how you would use that as a card indicator. Are you confusing
 functions and lists? Do you mean t[n] where n is an index into a list
 called t? Then if t held all the card values (or names) n could indicate
 one particular card. That might work.

 Another way could be a dictionary with a coded name per card as the key
 along with the value. (Aces pose a problem regardless of solution because
 they have two values)

 I could go that way, or code it as t1, t2, t3, etc.

 Having 52 variables, one per card could work but seems clumsy.
 Also figuring out how to deal a hand would be tricky with discreet 
 variables.

 Which way is the right and correct way to go?

 There is no single right way, but a collection of some sort sounds
 better than a set of independant variables.

 Also for blackjack, I want to use it as playertotal = playertotal + n,
 and computertotal = computertotal + n. or 1,2,3, etc. Which is better?

 I don't understand that bit at all?! What does 'n'represent?
 What are the 1,2,3 for?

 Alan G.
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need advice about which way to go.

2005-08-03 Thread Bob Gailer


At 11:12 AM 8/3/2005, Nathan Pinno wrote:
Sorry about that, I thought it
was clear that n = number randomly chosen. I 
was thinking of if the number was a five, it would choose a card with a
five 
on it. I don't want to have to code stuff that I have to repeat again and

again.
That's what classes, loops and functions are for.
I'm not worrying about card
types, I have that figured out separately.
The two games are indeed separate, too much trouble to do them a 1
program 
that can play both games.
Maybe I should have shown my code and asked using the code as a visual

reference.
Good idea. How about now?

Bob Gailer
phone 510 978 4454 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need advice about which way to go.

2005-08-03 Thread Nathan Pinno



Here is the code then:
#This is code for a blackjack game.
import randomcash = 0new_cash = 100cards = {"Ace", "Two", 
"Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", 
"Queen", "King"}card_types = {"Diamond", "Heart", "Spade", "Club"}bet = 
0playertotal = 0comp_total = 0

def menu(): print "1. Bet and 
play." print "2. Cash out and Exit"

def option(): return int(raw_input("Menu choice: 
"))

def card_choice(): return 
random.choice(range(1,14)

def types(): return random.choice(range(1,5)

def player_cards(): print a," of 
",t1 print b," of ",t2

print "Blackjack"print "By Nathan Pinno"while 
1: menu() choice = 
option() if choice == 
1: bet = int(raw_input("How much 
do you want to bet: 
") while 
1: if bet 
 
new_cash: 
print "Sorry, you don't have that much cash! Your total cash is: 
$",new_cash 
else: 
break a,b = 
card_choice() t1,t2 = 
types() if t1 == 
1: t1 = 
card_types[0] elif t1 == 
2: t1 = 
cardtypes[1] elif t1 == 
3: t1 = 
cardtypes[2] 
else: t1 = 
cardtypes[3] if a == 
1: a = 
cards[0] 
playertotal = playertotal + 1 elif 
a == 2: a 
= cards[1] 
playertotal = playertotal + 2 
Now do you have an idea of what I'm pointing to?

  - Original Message - 
  From: 
  Bob 
  Gailer 
  To: Nathan Pinno ; Tutor mailing list 
  
  Sent: Wednesday, August 03, 2005 12:28 
  PM
  Subject: Re: [Tutor] I need advice about 
  which way to go.
  At 11:12 AM 8/3/2005, Nathan Pinno wrote:
  Sorry about that, I thought it 
was clear that n = number randomly chosen. I was thinking of if the 
number was a five, it would choose a card with a five on it. I don't 
want to have to code stuff that I have to repeat again and 
  again.That's what classes, loops and functions are 
  for.
  I'm not worrying about card 
types, I have that figured out separately.The two games are indeed 
separate, too much trouble to do them a 1 program that can play both 
games.Maybe I should have shown my code and asked using the code as a 
visual reference.Good idea. How about now?
  Bob Gailerphone 510 978 4454 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need advice about which way to go.

2005-08-03 Thread Bob Gailer


At 11:36 AM 8/3/2005, Nathan Pinno wrote:
Here is the code
then:
I'll throw in some suggestions. 1 - check for balanced parentheses. This
has bit you before and you have several lines below with unbalanced
parentheses. 2 - since Python indexes start at 0, take advantage of this.
Use random.choice(range(13) and use the value to index the cards
list.
#This is code for a blackjack
game.
import random
cash = 0
new_cash = 100
cards = {Ace, Two, Three,
Four, Five, Six, Seven,
Eight, Nine, Ten, Jack,
Queen, King}
card_types = {Diamond, Heart, Spade,
Club}
bet = 0
playertotal = 0
comp_total = 0

def menu():
 print 1. Bet and play.
 print 2. Cash out and Exit

def option():
 return int(raw_input(Menu choice: ))

def card_choice():
 return random.choice(range(1,14)
This will return one number. The statement below (a,b = card_choice())
expects a tuple of 2 numbers to be returned.
def types():
 return random.choice(range(1,5)

def player_cards():
 print a, of ,t1
 print b, of ,t2

print Blackjack
print By Nathan Pinno
while 1:
 menu()
 choice = option()
 if choice == 1:
 bet = int(raw_input(How
much do you want to bet: )
Something is wrong with the indentation below. Assuming the if and else
following the while are indented more, you have a BIG problem. What will
happen if bet  new_cash? Endless loop printing the Sorry...
forever

while 1:
 if bet
 new_cash:

print Sorry, you don't have that much cash! Your total cash is:
$,new_cash

else:

break
 a,b = card_choice()
 t1,t2 = types()
 if t1 == 1:
 t1 =
card_types[0]
 elif t1 == 2:
 t1 =
cardtypes[1]
 elif t1 == 3:
 t1 =
cardtypes[2]
 else:
 t1 =
cardtypes[3]
Why not just use the random integer as an index? If you use range(13)
these if/elifs become
 t1 =
cardtypes[t1]

if a == 1:
 a =
cards[0]

playertotal = playertotal + 1
 elif a == 2:
 a =
cards[1]

playertotal = playertotal + 2
Same thing here. 
What are the functions of b, t2, and playertotal? Especially for those of
us who don't know blackjack.
Does that help?

Bob Gailer
phone 510 978 4454 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need advice about which way to go.

2005-08-03 Thread Nathan Pinno



Playertotal is for calculating the total of the player's hand. This is 
important, because if the player's total is greater than 21, he loses in 
Blackjack. B is for the second card in the player's hand and t2 was for the 
second card's type (i.e Heart, Diamond, Club, or Spade)

  - Original Message - 
  From: 
  Bob 
  Gailer 
  To: Nathan Pinno ; Tutor mailing list ; 
  Yoo, Danny 
  Sent: Wednesday, August 03, 2005 1:03 
  PM
  Subject: Re: [Tutor] I need advice about 
  which way to go.
  At 11:36 AM 8/3/2005, Nathan Pinno wrote:
  Here is the code 
  then:I'll throw in some suggestions. 1 - check for balanced 
  parentheses. This has bit you before and you have several lines below with 
  unbalanced parentheses. 2 - since Python indexes start at 0, take advantage of 
  this. Use random.choice(range(13) and use the value to index the cards 
  list.
  #This is code for a blackjack 
game.import randomcash = 0new_cash = 100cards = {"Ace", 
"Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", 
"Jack", "Queen", "King"}card_types = {"Diamond", "Heart", "Spade", 
"Club"}bet = 0playertotal = 0comp_total = 0def 
menu(): print "1. Bet and play." 
print "2. Cash out and Exit"def 
option(): return int(raw_input("Menu choice: 
"))def card_choice(): return 
random.choice(range(1,14)
  This will return one number. The statement below (a,b = 
  card_choice()) expects a tuple of 2 numbers to be returned.How do I 
  make it return two numbers?
  def 
types(): return 
random.choice(range(1,5)def 
player_cards(): print a," of 
",t1 print b," of ",t2print 
"Blackjack"print "By Nathan Pinno"while 1: 
menu() choice = option() if 
choice == 1: bet = 
int(raw_input("How much do you want to bet: ")
  Something is wrong with the indentation below. Assuming the if and 
  else following the while are indented more, you have a BIG problem. What will 
  happen if bet  new_cash? Endless loop printing the Sorry... forever
  
  Thanks, I forgot about that. I have to add bet = int(raw_input("Bet: 
  "))
   while 
  1: if 
  bet  
  new_cash: 
  print "Sorry, you don't have that much cash! Your total cash is: 
  $",new_cash 
  else: 
  break a,b = 
  card_choice() t1,t2 = 
  types() if t1 == 
  1: t1 = 
  card_types[0] elif t1 == 
  2: t1 = 
  cardtypes[1] elif t1 == 
  3: t1 = 
  cardtypes[2] 
  else: t1 
  = cardtypes[3]Why not just use the random integer as an index? If 
  you use range(13) these if/elifs 
  become 
  t1 = cardtypes[t1]
   if a == 
1: a = 
cards[0] 
playertotal = playertotal + 1 
elif a == 
2: a = 
cards[1] 
playertotal = playertotal + 2
  Same thing here. What are the functions of b, t2, and 
  playertotal? Especially for those of us who don't know blackjack.Does 
  that help?
  
  It helps some, but if you could answer my question above about how to 
  return two random numbers, it would be appreciated.
  Bob Gailerphone 510 978 4454 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need advice about which way to go.

2005-08-03 Thread Alan G
 cards = {Ace, Two, Three, Four, Five, Six, Seven, 
 Eight,
   Nine, Ten, Jack, Queen, King}
 card_types = {Diamond, Heart, Spade, Club}

{} means they are dictionaries but you don;t provide key:value pairs.
You probably want lists here not dictionaries.

You can read about the differences in the Raw Materials topic of my 
tutorial.

if t1 == 1:
t1 = card_types[0]

And you don't have a '0' key in your dictionaries so this will fail.

 Now do you have an idea of what I'm pointing to?

I think we get the idea but you need to think about what exactly your 
data looks like.
Why not break the program into bits, just write a small program that 
draws cards,
or deals a small hand - two cards for blackjack! Once you have that 
working just
get the basic rules sorted out so you can play the game. Then add the 
money
bits once you have a working game.

This kind of evolutionary development is how most programmers build
up their code. Try sometjing oin the interpreter, turn it into a 
simple
program that does one key thing right. Test it. Once it works go back
to the interpreter and try the next bit, write it into the program.
Test it and get it working. Check the oroiginal stuff still works too.
Repeat until done.

Its this interpreter/editor/test loop that makes Python such a 
powerful
development tool.

HTH,

Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld 

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need advice.

2005-08-02 Thread Alan G
 I want to write a program that will convert time in any other 
 time zone to my time zone. 

This is a deceptively complex task. There are around 40 timezones
varying by anything from 15 minutes to 2 hours. And some places 
change timezone throughout the year. Others have multiple daylight 
saving dates etc etc.

 Would it be better to use the Python time molecule 

Use the force Luke...
If a standrad module exists then its almost certain that more 
thought and debugging has gone into it than you want to expend!
Use what's there and tweak it to suit your needs.

HTH,

Alan G.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need advice.

2005-08-02 Thread Alan G

 I forgot to tell that I use Python 2.2.3. When I first got Python, I 
 got
 2.4.1, but it refused to run the second time. So I went and got 
 2.2.3. Your answer would make sense if I had 2.4.1, but I don't.

Version 2.3 should work and has the datetime stuff I think
- just checked and it does...

But 2.4 should work too, although I confess I haven't tried 2.4 yet 
except
for cygwin. So it might be worth having another go at installing 2.4.

Alan G.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] I need advice.

2005-08-02 Thread Nathan Pinno
I think I'll leave this one for someone else. I got too confused too quick.
- Original Message - 
From: Alan G [EMAIL PROTECTED]
To: Nathan Pinno [EMAIL PROTECTED]; Tutor mailing list 
tutor@python.org
Sent: Tuesday, August 02, 2005 1:47 AM
Subject: Re: [Tutor] I need advice.


 I want to write a program that will convert time in any other time zone 
 to my time zone.

 This is a deceptively complex task. There are around 40 timezones
 varying by anything from 15 minutes to 2 hours. And some places change 
 timezone throughout the year. Others have multiple daylight saving dates 
 etc etc.

 Would it be better to use the Python time molecule

 Use the force Luke...
 If a standrad module exists then its almost certain that more thought and 
 debugging has gone into it than you want to expend!
 Use what's there and tweak it to suit your needs.

 HTH,

 Alan G.
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor