I need help writing this program, any hints, help, guidance will be appreciated.
The program needs to provide a menu to the user with the following options:

Reset the deck
Shuffle the deck
Cut the deck
Cut to a card.
Cut against the computer

Each of these options must work. You must include at least one of each of the following:

Decision structure
Repetitive structure
array (if you use one in your object it will count)
Object (The one in Exercise 11 counts)
4 Years
Discussion Span
Last Post by HiHe

Looks pretty standars stuff found in many codes in our Code Snippet section. Cut is usually not done but it would be simple to do:

Determine cut_point
deck = deck[cut_point:] + deck[:cut_point]
#Jason Edgel#
#Program for deck of cards#

class deck_of_cards:
    #Making the deck#
    def __init__(self):
        self.__cards = []

    #Reset the Deck#
    def resetdeck(self):
        del self.__cards[0:]
        for suit in range(1,5):
            for value in range(1,14):

    #Shuffle the Deck#
    def shuffle(self):

    #Cut the Deck#
    def cutdeck(self):
        cutdeck1 = self.__cards[:26]
        cutdeck2 = self.__cards[26:]
        self.__cards = cutdeck2 + cutdeck1

    #Cut to a card#
    def cuttocard(self):
        print self.__cards[-1]

    #Cut to the highest card and have it win#
    def cutCPU(self):
        playerTop = self.__cards[-1]
        del self.__cards[-1]
        compTop = self.__cards[-1]
        del self.__cards[-1]
        print "Player", "Computer"
        print ""
        print playerTop," ", compTop

    #Return to cards#
    def get_cards(self):
        return self.__cards

    #Program that uses the class I made above#

    import random

    def main():
        getcard = deck()
        menuloop = 1
    #Menu loop#
        while menuloop == 1:
            print ""
            print "1. Reset the deck"
            print "2. Shuffle the deck"
            print "3. Cut the deck"
            print "4. Cut to a card"
            print "5. Cut against the computer"
            print "6. Exit the program"
            print ""
uM = input("Select a menu option(#): ")
print ""
if uM == 1:
    print getcard.get_cards()

    if uM == 2:
        print getcard.get_cards()

    if uM == 3:
        print getcard.get_cards()

    if uM == 4:

    if uM == 5:

    #End the loop#
    if uM == 6:
        print "Thanks for playing"
        menuloop = 0

    #Defensive if statement, only accepts #'s 1-7#
    if uM != 1 and uM != 2 and uM != 3 and uM != 4 and uM != 5 and uM != 6 and uM != 7:
        print "Wrong input entered"


You are printing menu by the main function after checking the input, which I find strange, especially since it is endless loop printing the menu. You have also defined this function inside the class with missing self parameter, but you call it like free function. Why are not using else instead of separate if at end? Also the alternatives are exclusive and should be elif in single if. deck is not defined in main also and you have no instance of deck_of_cards in your program. By convention the class name should also be in CapitalizedWordsFormat.

Also you have uM tested for other values inside if which ensures uM is 1, so the other if conditions can never be True.

Edited by pyTony

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.