Updating cards in deck loop issue [closed]

asked 2017-03-28 10:52:04 -0500

After playing a round, the cards are removed, but if I play again, (if I click yes), it goes back to 52 cards again. It didn't remove the cards that has been removed in the previous game.I think its loop issue because I am calling mainfuction in the end and it goes back to the first stage and ignoring the cards that been deleted before I just want to ask if any of you can guide me or help me in updating the cards in the deck if yes is click thank you alot

Below is code:

import random, sys

# define global variables for the cards

suits = ('Clubs', 'Spades', 'Hearts', 'Diamonds')
pip = ('Ace', '2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King')
pipValues = {'Ace':11, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, '10':10, 'Jack':10, 'Queen':10, 'King':10}



class Card:

    #When you create an instance of Card, you pass it a suit ("C", "D", "H", or "S") and a "pip" (2, 3, 4, 5, 6, 7, 8, 9, 10 J, Q, K, A).
    #These values should be stored as instance variables for the new card object.
    #I recommend you also have an instance variable "value" that stores the point value of the card.
    #It should have an __str__ method that lets you print an individual card (such as "3S" for three of spades).
    #Note that the __str__ method for Decks should take advantage of the __str__ method for Cards.

    def __init__(self, suit, pip):
        self.suit = suit
        self.pip = pip
        self.value = pipValues.get(pip)

    def __str__(self):
        thisCard = ""
        thisCard += str(self.pip)
        thisCard += str(self.suit)
        return (thisCard)

    def __repr__(self):
        thisCard = ""
        thisCard += str(self.pip)
        thisCard += str(self.suit)
        return (thisCard)




class Player:

    #When you create an instance of Player, it should have an instance variable "hand" that's set to an empty list,
        #and an instance variable "handTotal" that's set to zero. These instance variables will be modified
        #by Deck's "dealOne()" method.
    #It should have an __str__ method that lets you print out a Player's hand.



    def __init__(self):
        self.hand = []
        self.handTotal = 0

    def __str__(self):
        printHand = ""
        for i in self.hand:
            printHand += str(i) + " "
        return (printHand)

    def __repr__(self):
        printHand = ""
        for i in self.hand:
            printHand += str(i) + " "
        return (printHand)


class Deck:

    #When you create an instance of Deck, it should add 52 Card objects to an instance variable "cardList".
    #It should have a shuffle() method that rearranges the cards in cardList. You can do this easily by importing the
        #"random" package into Python, and using the random.shuffle() method. random.shuffle(myList) rearranges the
        #elements of the list "myList" into a random order.
    #It should have a dealOne() method that removes the first card from your deck's cardList, and appends it to the
        #hand of a specified player.
    #It should have an __str__ method that lets you print out the entire deck for debugging ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by sideburns
close date 2017-03-28 14:36:58.289619

Comments

1

@aikachiq wtf?? Welcome to ASKFEDORA but I think this is a python language problem not related to Fedora Itself I think you can get more audience to solve your problem, asking in a sites like stackexchange

hhlp gravatar imagehhlp ( 2017-03-28 11:01:32 -0500 )edit