ActiveState Code

Recipe 533113: (untitled)


Python
1
     

Comments

  1. 1. At 10:56 a.m. on 27 sep 2007, Bosko M said:

    refactor. Try refactoring your code by using functions, they will make it more readable. Your variable names are often meaningless (like qq, etc.) it's a bad practice. Command 'clear' does not exist on Win. Tip: Defining cards could be much shorter than c2 = ( ) ...,

    example:

    cards = [] for card_number in range(2,11)+ ['jack','queen','king','ace]:

    for card_color in ('spades', 'clubs', 'hearts', 'diamonds'):

    if isinstance(card_number, int):
    
      card_value = card_number
    
    elif card_number = 'ace':
    
      card_value = 11
    
    else:
    
      card_value = 10
    cards.append( (str(card_number) + ' of ' + card_color, card_value) )
    

    And extracting names: card_names = [card[0] for card in cards]

    Obviously, comments are not suitable for posting code :(

  2. 2. At 4:53 a.m. on 28 sep 2007, dewi roberts (the author) said:

    Response. Thanks Bosko for taking the time to look at my python code for pontoon, i have only recently started to learn python and have a long way to go, but i will try to adress each point you raised -but it will have to wait until November - my schedule for next 6 weeks is very busy. Many Thanks Dewi

Sign in to comment