Sunday, January 25, 2015

Making & Shuffling a Deck of Cards - Homework 2

For this next week's homework, we have to create a simple program where you created a deck of cards and shuffle it for the first part. 

Then we also have to created a way for the person running the code decide how many decks to shuffle at once.

Here is what I made:

#Assignment002_ChristianMunoz.py
#01/25/2014
from random import randint
import math

#make the list of cards
def makeListOfCards(stringOfCards):

    listOfCards = stringOfCards.split()

    return listOfCards

#shuffle code
def shuffleDeck(inputDecks):

    shuffledDeck = []

    for i in range(len(inputDecks)):

        tempInt = randint(0,len(inputDecks) - 1)
        shuffledDeck.append(inputDecks.pop(tempInt))

    return(shuffledDeck)

#main function
def main():
    
    decksToShuffle = eval(input("Enter how many decks you would like to shuffle at once (1-5):  "))

    #This checks to make sure the entry is a valid entry
    if decksToShuffle <= 0 or decksToShuffle > 5:
        print("That is not a valid entry!")
        main()

    #If the entry was valid, then execute code
    else:
        CardSymbols = '''AS AH AD AC
                         KS KH KD KC
                         QS QH QD QC
                         JS JH JD JC
                         10S 10H 10D 10C
                         9S 9H 9D 9C
                         8S 8H 8D 8C
                         7S 7H 7D 7C
                         6S 6H 6D 6C
                         5S 5H 5D 5C
                         4S 4H 4D 4C
                         3S 3H 3D 3C
                         2S 2H 2D 2C'''
        
        listOfCards = makeListOfCards(CardSymbols) * decksToShuffle
        
        print(shuffleDeck(listOfCards))

main()

I still have to make another little program that works almost the same way, but with dice. This is all for now, thanks for reading!

No comments:

Post a Comment