Question

In: Computer Science

Build a two dimensional array out of the following three lists. The array will represent a...

Build a two dimensional array out of the following three lists. The array will represent a deck of cards. The values in dCardValues correspond to the card names in dCardNames. Note that when you make an array all data types must be the same. Apply dSuits to dCardValues and dCardNames by assigning a suit to each set of 13 elements.

  1. dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
  2. dCardValues = ['2','3','4','5','6','7','8','9','10','11','12','13','14']
  3. dSuits = ["Clubs","Spades","Diamonds","Hearts"]

Once assigned your two dimensional array should resemble this :

2 Clubs 2
3 Clubs 3
4 Clubs 4
5 Clubs 5
6 Clubs 6
7 Clubs 7
8 Clubs 8
9 Clubs 9
10 Clubs 10
J Clubs 11

Q Clubs 12
K Clubs 13
A Clubs 14
2 Spades 2
3 Spades 3
4 Spades 4
5 Spades 5
6 Spades 6
7 Spades 7
8 Spades 8
9 Spades 9
10 Spades 10
J Spades 11
Q Spades 12
K Spades 13
A Spades 14
2 Diamonds 2
3 Diamonds 3
4 Diamonds 4
5 Diamonds 5
6 Diamonds 6
7 Diamonds 7
8 Diamonds 8
9 Diamonds 9
10 Diamonds 10
J Diamonds 11
Q Diamonds 12
K Diamonds 13
A Diamonds 14
2 Hearts 2
3 Hearts 3
4 Hearts 4
5 Hearts 5
6 Hearts 6
7 Hearts 7
8 Hearts 8
9 Hearts 9
10 Hearts 10
J Hearts 11
Q Hearts 12
K Hearts 13
A Hearts 14

Once you have this two dimensional array, you should shuffle it either by function or by code to produce a shuffled deck of cards.

Randomly choose and extract five cards from the deck.

After that apply the selection sort to the two dimensional array returning it to it original state as listed above. Display the 5 cards selected and their indexes. Display the remaining deck with its indexes.  

Reshuffle and apply the insertion and selection sort.
IN PYTHON

Solutions

Expert Solution

import random

dCardNames = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']

dCardValues = ['2','3','4','5','6','7','8','9','10','11','12','13','14']

dSuits = ["Clubs","Spades","Diamonds","Hearts"]

def shuffle(deck):

for i in range(len(deck)-1,0,-1):

r = random.randint(0,i)

deck[i],deck[r]=deck[r],deck[i]

return deck

Deck = []

for suit in dSuits:

for index in range(13):

card = [dCardNames[index], suit, dCardValues[index]]

Deck.append(card)

# print(dCardNames[index], dCardValues[index])

print(Deck)

Deck = shuffle(Deck)

print(Deck)

selected = []

for i in range(5):

r = random.randint(0,56)

selected.append(Deck[i])

# print(selected)

selected_index= []

def sort(deck):

size = 0

for suit in dSuits:

for index in range(13):

card = [dCardNames[index], suit, dCardValues[index]]

for i in range(len(deck)):

if deck[i] == card:

if card in selected:

selected_index.append([i,card])

temp = deck[i]

deck[i] = deck[size]

deck[size] = temp

size = size+1

return deck

Deck = sort(Deck)

print(Deck)

print(selected_index)


/////////////////////////////////END////////////////////////

# Feel free to ask questions in the comment section

# Hit the like if my answer if it is worth helping to you.

# you can payback and help me with a like.


Related Solutions

C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
For this lab, you will work with two-dimensional lists in Python. Do the following: Write a...
For this lab, you will work with two-dimensional lists in Python. Do the following: Write a function that returns the sum of all the elements in a specified column in a matrix using the following header: def sumColumn(matrix, columnIndex) Write a function display() that displays the elements in a matrix row by row, where the values in each row are displayed on a separate line. Use a single space to separate different values. Sample output from this function when it...
you will create a dynamic two dimensional array of mult_div_values structs (defined below). The two dimensional...
you will create a dynamic two dimensional array of mult_div_values structs (defined below). The two dimensional array will be used to store the rows and columns of a multiplication and division table. Note that the table will start at 1 instead of zero, to prevent causing a divide-by-zero error in the division table! struct mult_div_values { int mult; float div; }; The program needs to read the number of rows and columns from the user as command line arguments. You...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to fill the 2-dimensional array with (random numbers, range 0 - 30). The array has rows (ROW) and columns (COL), where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to...
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: 1. Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. 2. Create a method to print the array. 3. Create a method to find the largest element in the array 4. Create a method to find the smallest element in the array 5....
Write a Java program that will use a two-dimensional array and modularity to solve the following...
Write a Java program that will use a two-dimensional array and modularity to solve the following tasks: Create a method to generate a 2-dimensional array (random numbers, range 0 - 500). The array has ROW rows and COL columns, where ROW and COL are class constants. Create a method to print the array. Create a method to find the largest element in the array Create a method to find the smallest element in the array Create a method to find...
How to create a two-dimensional array, initializing elements in the array and access an element in...
How to create a two-dimensional array, initializing elements in the array and access an element in the array using PHP, C# and Python? Provide code examples for each of these programming languages. [10pt] PHP C# Python Create a two-dimensional array Initializing elements in the array Access an element in the array
1.Declare a two-dimensional array of Strings namedchessboard.
1. Declare a two-dimensional array of Strings named chessboard.2. Declare a two-dimensional array of integers named tictactoe.3. Declare and create a two-dimensional array of chars,tictactoe, with 3 rows, each with 3 elements.4. Create a two-dimensional array of ints, plan, with 2 rows, and and 3 columns and initialize the first row to 8, 20, 50 and the second row to 12, 30, 75. Use member initializer syntax.
In C Create a multi-dimensional array and print it out forwards, backwards and then transpose.
In C Create a multi-dimensional array and print it out forwards, backwards and then transpose.
Provide code samples for the following in C#a. Declare a two-dimensional array of integers names...
Provide code samples for the following in C#a. Declare a two-dimensional array of integers names intArray17.b. Create a loop to calculate the sum of every element in the first column.c. Create a loop to calculate the sum of every element in the array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT