In: Computer Science
Use Python to solve: show all work
1) Write a program that prints out a deck of cards, in the format specified below. (That is, the following should be the output of your code).
2 of hearts
2 of diamonds
2 of spades
2 of clubs
3 of hearts
3 of diamonds
3 of spades
3 of clubs
4 of hearts
4 of diamonds
4 of spades
4 of clubs
Continue with 5,6,7.. ending with
A of hearts
A of diamonds
A of spades
A of clubs
Start your program by defining the following two lists.
suits = ["hearts", "diamonds", "spades", "clubs"]
ranks = [“2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”, “10”, “J”, “Q”, “K”, “A”]
Remember you can use the for statement to get elements of a list.
For example if lst = ["A","B","C"] then
for elem in lst:
print (elem)
would print
A
B
C
PYTHON CODE:
# list to store the suits
suits = ["hearts", "diamonds", "spades", "clubs"]
# list to store the ranks
ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q",
"K", "A"]
# iterating through the rank list
for rank in ranks:
# iterating through the suit list
for suit in suits:
# printing the string
in the required format
print("{0:s} of
{1:s}".format(rank,suit))
SCREENSHOT FOR CODING:
SCREENSHOT FOR OUTPUT: