Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python. Make a function that when called returns one card from the deck. make a deep copy of the given code. Rules: - When

In Python. Make a function that when called returns one card from the deck. make a deep copy of the given code.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Rules: - When a card is printed from the function it is taken out of the deck - If the deck is empty print 'There are no more cards' from the function - Every call to the function returns one card. - A fresh deck can be made at any time - The function is called by asking the user how many cards they want to draw. One card is printed in the function each time it is called. - After drawing the user's cards, ask if they want to draw more cards from that deck, draw from a new deck (if so, then ask how many cards), or quit. Cand deck = [['Ace of Spades', 'King of Spades', I 'Queen of Spades', "Jack of Spades', I '10 of Spades', "9 of Spades', I '8 of Spades", 7 of Spades', 1 " 6 of Spades", "5 of Spades", I "4 of Spades", "3 of Spades", I "2 of Spades"], I ['Ace of Diamonds', "King of Diamonds', I 'Queen of Diamonds', 'Jack of Diamonds', I '10 of Diamonds', "9 of Diamonds', I " 8 of Diamonds", "7 of Diamonds', 1 " 6 of Diamonds", "5 of Diamonds', I "4 of Diamonds", '3 of Diamonds", I "2 of Diamonds'], ['Ace of Clubs', 'King of Clubs', I "Queen of Clubs", "Jack of Clubs", I "10 of Clubs", "9 of Clubs", I '8 of Clubs", '7 of Clubs', '6 of Clubs', '5 of Clubs', "4 of Clubs", '3 of Clubs', '2 of Clubs'],1 [Ace of Hearts', 'King of Hearts', 'Queen of Hearts', 'Jack of Hearts', I 10 of Hearts', 9 of Hearts', 1 '8 of Hearts', '7 of Hearts', '6 of Hearts', '5 of Hearts', '4 of Hearts', '3 of Hearts', '2 of Hearts'] Takes no values and returns no values In one while statement - Check to see if your game deck is empty (length is zero) - If so, tell the user that there are no more cards and break out of the while, effectively ending the function - You can else: continue or just not do an else - Populate a variable with a random number between 0 and the current length of the game deck (minus 1). This will choose a random suit (hearts, diamonds, etc) from the suits that are still populated with cards. - Check to see if that random suit is empty (length is zero) - If so, delete that suit and continue, returning control to the top of the while statement - You would delete game deck[suit number] - Populate a variable with a random number between 0 and the current length of the randomly chosen suit (minus one) - Print that card - Game deck[suit number][card number] - Delete that card from the current game deck - break Your body: Let the user know the deck has been shuffled Inside another while True: - Ask how many cards the user wants to draw - Use error checking to make sure they gave an integer. If not, warn them and continue. Use try/except and try casting the user input to an integer int(). - Use a For statement to call the card drawing function as many times as the user requested - Give the user the choices to draw again from the same deck, shuffle and draw or quit - Get the input, use IF/ELF/ELSE - If they quit, break - If they want to shuffle, deep copy the game deck from the original deck again, let them know it has been shuffled, then continue - If they quit, just continue After the while, use one input thanking the user for playing and telling them to hit enter to exit the script

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle9i Database Administrator Implementation And Administration

Authors: Carol McCullough-Dieter

1st Edition

0619159006, 978-0619159009

Students also viewed these Databases questions

Question

Identify the types of informal reports.

Answered: 1 week ago

Question

Write messages that are used for the various stages of collection.

Answered: 1 week ago