[Tutor] deck dealing program

Nathan Pinno falcon3166 at hotmail.com
Tue Aug 9 22:52:23 CEST 2005


Thanks Luke. You've helped me out of a jam that I was going to ask without even asking.

Nathan
---------------------------------------------------------------
Early to bed,
Early to rise,
Makes a man healthy, wealthy, and wise.
--Benjamin Franklin
-------------------------------------------------------------------
  ----- Original Message ----- 
  From: luke 
  To: tutor at python.org 
  Sent: Monday, August 08, 2005 12:38 AM
  Subject: [Tutor] deck dealing program


  from random import randint

  def identify_card(n):
      cardname = ""
      royals = ["Jack","Queen","King","Ace"]
      temp = n % 13
      if temp > 8:
          cardname += royals[temp-9]
      else:
          cardname += str(temp+2)
      cardname += " of "

      suits = ["Spades","Hearts","Diamonds","Clubs"]
      cardname += suits[n/13]
      return cardname

  def main():
      deck = range(52)
      cards = []
      while 1:
          x = raw_input("how many cards do you want? ")
          try:
              x = int(x)
          except ValueError:
              print "Invalid value exiting for I have no error code. Please use an int next time."
              raise SystemExit
          if x <= 52 and x >= 0:
              y = 0
              while y < x:
                  cards.append(identify_card(deck.pop(randint(0,len(deck)-1))))
                  y += 1
              break
      print cards
  if __name__ == "__main__":
      main()

  #Luke


------------------------------------------------------------------------------


  _______________________________________________
  Tutor maillist  -  Tutor at python.org
  http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050809/d4d4a8e0/attachment.htm


More information about the Tutor mailing list