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

Alan G alan.gauld at freenet.co.uk
Wed Aug 3 23:45:46 CEST 2005

> 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 

>        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 
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 
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 
development tool.


Alan G
Author of the Learn to Program web tutor

More information about the Tutor mailing list