list - Assigning Location to Card in Simply Python Card Game -



list - Assigning Location to Card in Simply Python Card Game -

i'm working on homework assignment create simple card game, , don't understand why can't utilize same method create start deck , assign start location of cards also. we're not supposed utilize more complicated lists , arrays (because that's we've learned far).

the first part (that builds deck) works fine. sec part that's supposed assign location (of "deck", later i'll set in locations of "player hand" , "computer hand" deal cards) doesn't work , don't why can't utilize same method. maintain getting error "list index out of range" , can't figure out how prepare it.

def startdeck(): suitname = ("hearts", "diamonds", "spades", "clubs") rankname = ("ace", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "jack", "queen", "king") suitname = list(suitname) rankname = list(rankname) deck = [] suit in range(4): rank in range(13): card_string = rankname[rank] + " of " + suitname[suit] deck.append(card_string) homecoming deck def startcardloc(): deck = startdeck() locname = ("deck") deck = list(deck) locname = list(locname) cardloc = [] loc in range(52): firstloc in range(1): loc_string = locname[loc] cardloc.append(loc_string) homecoming cardloc print startcardloc()

here's traceback of error:

--------------------------------------------------------------------------- indexerror traceback (most recent phone call last) <ipython-input-1-6d73de457be8> in <module>() 24 homecoming cardloc 25 ---> 26 print startcardloc() <ipython-input-1-6d73de457be8> in startcardloc() 20 loc in range(52): 21 firstloc in range(1): ---> 22 loc_string = locname[loc] 23 cardloc.append(loc_string) 24 homecoming cardloc indexerror: list index out of range

thanks , help.

you should re-examine list(). phone call python built-in 4 times , doesn't seem necessary in case. in particular, locname = list(locname) assigning list ['d','e','c','k'] locname, not intended. line causing index error, later seek access locname[0] through locname[51] in loop.

python list playing-cards

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -