save - Card Game Python, Saving a shuffled deck -
i writing program in python user has guess if next card in pack of playing cards bigger or smaller previous card. i've got whole program work except 1 function.
i have 2 ways of playing game. 1 way shuffle deck of cards , other way play un-shuffled deck of cards (some random order put them in when making text file). want when user selects play shuffled deck, shuffled deck saved , overwrites un-shuffled deck's text file.
the cards in text file saved 2 or 3 digit numbers.
each suit numbered follows:
- 1 - clubs
- 2 - diamonds
- 3 - hearts
- 4 - spades
as far card numbers go:
- 1 - ace
- 2 - two
- ...
- 11 - jack
- 12 - queen
- 13 - king
so 5 of hearts saved 35, , jack of clubs saved 110
here code far.
this attempt @ saving:
def saveshuffleddeck(deck): currentfile = open('deck.txt', 'w') count = 1 count in range(1,52+1): cardtoaddtofile = str(deck[count].suit) + str(deck[count].rank) + '\n' currentfile.write(cardtoaddtofile) currentfile.close()
if see rest of code deck, check out this pastebin link
might want give read: http://docs.python.org/2.7/library/functions.html#open
open('deck.txt', 'w') # overwrite
and this...
import random f = open('deck.txt', 'w') # op l = [i in range(1,111)] # list 1 110 random.shuffle(l) # shuffle list in l: f.write(str(i)) f.write('\n')
edit: sorry, did not use functions. modify though.
Comments
Post a Comment