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

Use your chapter 6 deck of cards assignment. Write each card of your shuffled de

ID: 3572196 • Letter: U

Question

Use your chapter 6 deck of cards assignment. Write each card of your shuffled deck to a file named shuffledDeck.dat Read each card in a loop and display the card to the console. The user should be able to hit the enter key to see the next card. End the loop when all cards have been dealt. Allow the user to shuffle again and output or quit the program. Name your program shuffledDeck.py ZIP all your files into a file name program5.zip and upload to Moodle import random suits * ("clubs", "diamonds", "hearts", "spades") cards - ("ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "queen", "Icing"] decic = t) count * 0 for suit in range(0, 4): for card in range(0, 13): declc.append(cards[card] + "-" + suits [suit]) print (decic (count]) count = count + 1 print f = open("shuffledDeck.dat", V) opens file with name of "shuffledDeck.dat" whacks any previous file with the "w" for cardines in range(0, 52): tempCard = deck[cardlr.dex] randoalndex = random.randint(0, 51) deck [cardlndex] = deck[rar.dosIr.dex] deck[randomIndex] * tempCard for cardlndex in range(0, 52): f.write(str(deck[cardlndex]) + " ") f.close!)

Explanation / Answer

import random
suits = ["clubs","diamonds","hearts","spades"]
cards = ["ace","2","3","4","5","6","7","8","9","10","jack","queen","king"]
deck = []
count =0
for suit in range(0,4):
for card in range(0,13):
deck.append(cards[card]+"-"+suits[suit])
#waiting for the user to hit enter
a = raw_input(">")
if a==" ":
print(deck[count])
count = count +1
print("----------------------------------")
f = open("shuffledDeck.dat","w")
for cardIndex in range(0,52):
tempCard = deck[cardIndex]
randomIndex = random.randint(0,51)
deck[cardIndex] = deck[randomIndex]
deck[randomIndex] = tempCard
for cardIndex in range(0,52):
f.write(str(deck[cardIndex])+" ")
f.close()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote