Question: Can the following code be modified to allow the user to pick 1 card and have the program determine the secret card? The program works,
Can the following code be modified to allow the user to pick card and have the program determine the secret card? The program works, but it is having trouble determining the secret card. Please keep psudedocode and variables the same. Thanks!
#CardTrick.py
import random
def main:
#declare variables
column
loopcounter
#declare the decklist
deck
#declare a row by column array
cols
rows
play for in rangecols for in rangerows
#Opening Message
printWelcome Im am not the latest development in AI but,"
printIm a computer program that can perform a card trick"
printLets begin!
printBuilding the deck of cards..."
#Call Build Deck
BuildDeckdeck
printDeck built successfully!
seedeck inputWould you like to see the full deck yn
if seedeck.lowery:
#Call Print Deck
PrintDeckdeck
#Begin the Main Card Trick Loop
for loopcounter in range:
Dealdeck play
column intinputWhich column is your card in or :
PickUpdeck play, column
# Call SecretCard
SecretCarddeck
printThank you for playing the card trick!"
def BuildDeckdeck:
#define local variables
used
i
# Generate cards while the deck is full of intergers
while i :
# Generate a random interger between and
card random.randint
# Test to see if the value has already been used.
# If not, add it to the deck
if usedcard:
usedcard
decki card
i
#End while loop
#Call PrintCard
def PrintCardcard:
rank card
suit card
# Define Ranks
if rank :
cardString "King of
elif rank :
cardString "Ace of
elif rank :
cardString "Jack of
elif rank :
cardString "Queen of
else:
cardString frank of
# Define Suits
if suit :
cardString "Clubs"
elif suit :
cardString "Diamonds"
elif suit :
cardString "Hearts"
else:
cardString "Spades"
printfcardString: end
# Call PrintDeck
def PrintDeckdeck:
for i in range:
PrintCarddecki
if i :
print
# end for loop
def Dealdeck play:
# Define local variables
card
# Deal the cards from the deck to the play list
print
Column Column Column
print
#Begin nested for loop structure to deal out the cards
for row in range:
for column in range:
playrowcolumn deckcard
PrintCardplayrowcolumn
card
print
#end nested for loop structure
#Call PickUp
def PickUpdeck play, column:
# Define local variables
card
order columncolumn column
#Identify the order of columns and rows to pick up
for col in order:
for row in range:
deckcard playrowcol
card
# End for loop structure
def SecretCarddeck:
print
Finding Secret Card..."
for card in range:
PrintCarddeckcard
card
print
print
Your secret card is: end
PrintCarddeck
print
main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
