[Tutor] deck dealing program
luke
rabidpoobear at gmail.com
Mon Aug 8 20:20:29 CEST 2005
Just offering my take on the problem.
hope it helps someone.
----- Original Message -----
From: <python-tutor at toddmaynard.com>
To: <tutor at python.org>
Sent: Monday, August 08, 2005 2:02 AM
Subject: Re: [Tutor] deck dealing program
> Are you:
> a.) Having trouble with the code and looking for help?
> b.) Looking for suggestions on how to improve the code?
> c.) Offering the code as a demo for Nathan et al.?
>
> I was just doing stuff along the same lines and was having fun seeing the
> different approaches to the same problem.
>
> --Todd
>
> On Monday 08 August 2005 02:38 am, luke wrote:
> > 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
More information about the Tutor
mailing list