Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help can\'t display the cardds Problem Description: Write a program that display

ID: 3572976 • Letter: H

Question

help can't display the cardds Problem Description: Write a program that displays three cards randomly selected from a deck of 52, as shown in the Fig.1 below. The card image files are named 1.png, 2.png, ..., 52.png and stored in the image/card directory. All three cards are distinct and selected randomly. The image icons used in the exercises can be obtained from the book source code www.cs.armstrong.edu/liang/intro10e/book.zip file under the image folder (i.e., image/card/1.png) Fig. 1 Hint: You can select random cards by storing the numbers 1-52 to an array list, perform a random shuffle introduced in Section 11.12 and use the first three numbers in the array list as the file names for the image.

Explanation / Answer

import matplotlib.pyplot as plt
import random
cards = [i for i in range(1,53)]
random.shuffle(cards)
print cards
img1 = imread('image/card/'+cards[0]+'.png')
img2 = imread('image/card/'+cards[1]+'.png')
img3 = imread('image/card/'+cards[2]+'.png')
plt.close('all')
plt.subplot(2,2,1)
imshow(img1)
plt.subplot(2,2,2)
imshow(img2)
plt.subplot(2,2,3)
imshow(img3)
plt.show()