how to indent properly so that it would work at the command line import random s
ID: 3572403 • Letter: H
Question
how to indent properly so that it would work at the command line
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()
Explanation / Answer
Hi, I have indendented correctly.
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()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.