Question
urgent help with python. can somone code this please and show output
QUESTION: There are a variety of games possible with a deck of cards. A deck of cards has four different suits, i.e. spades (
The return for list shuffle will almost certainly be different than the sample outputs you see below. It makes sense because
import random import copy def deck ) t 11 1 -lst Returns a deck of cards as a list. Each element in the list is a list of a s
HINTS: Ynraarand First, you should import the random library import random then: random.sample (range (1, Max), N) return a l
QUESTION: There are a variety of games possible with a deck of cards. A deck of cards has four different suits, i.e. spades (*), clubs (*), diamonds (), hearts (), and thirteen values for each suit. Now write a function that uses list comprehension to create a deck of cards. Each element in the list will be a card, which is represented by a list containing the suit as a string and the value as an int. First, write a function called deck) that contains the deck of cards. Do not check test cases below) def deckO: O -> list Returns a deck of cards as a list. Each element in the list is a list of a string representing the suit C" spades", "clubs", "diamonds", or "hearts" and an integer representing the number of the card (1 to 13) Then write another function that receives the list representing the deck of cards and return a randomly shuffled list def random_shuffle(lst) (list) -> list Receives a list and returns a randomly ordered list containing all of the same elements. Finally, write a function that receives the list representing th e deck of cards returns the list in reverse er def reverse(lst): (list) - list Receives a list and returns a reverse ordered list containing all of the same elements
The return for list shuffle will almost certainly be different than the sample outputs you see below. It makes sense because you're shuffling them randomly every time: >>deckO LC'spades', 1], C' spades', 2], C'spades', 3], ['spades', 4], C'spades', 5], C'spades' 6], C'spades', 7], C'spades', 8], C'spades', 9], 'spades', 10], 'spades', 11], 'spades', 12], C' spades', 13], C'clubs', 1], C'clubs', 2], C'clubs', 3], C'clubs', 4], C'clubs', 5], ['clubs', 6], ['clubs', 7], ['clubs', 8], ['clubs', 9], ['clubs', 10], C'clubs, 11], C'clubs', 12], C'clubs', 13], C'diamonds', 1], C'diamonds', 2], ['diamonds', 3], C'diamonds', 4], ['diamonds', 5], ['diamonds', 6], C'diamonds', 7], ['diamonds', 8], ['diamonds' 9], 'diamonds, 10], C'diamonds', 11], C'diamonds', 12], ['diamonds 13], C'hearts', 1], C'hearts', 2], C'hearts', 3], C'hearts', 4], C'hearts', 5], C'hearts', 6], C'hearts', 7], C'hearts', 8], C'hearts', 9], C'hearts', 10], C'hearts', 11], C'hearts, 12], C'hearts', 13]] >>random shuffle(deckO) Different order of deck >>>random shuffle(deckO) Different order of deck >>random shuffle(deckO) Different order of deck >>>randomshuffle(deckO) Different order of deck >>>random shuffle(deckO) Different order of deck >>random shuffle(deckO) Different order of deck >>reverse deckO) LC'hearts', 13], C'hearts', 12], C'hearts', 11], ['hearts', 10], C'hearts', 9], ['hearts', 8], C'hearts, 7], C'hearts', 6], C'hearts', 5], C'hearts', 4], C'hearts', 3], 'hearts', 2], C'hearts', 1], 'diamonds', 13], C'diamonds', 12], ['diamonds' 11], C'diamonds', 10], ['diamonds', 9], ['diamonds', 8], C'diamonds', 7], C'diamonds 6], C'diamonds', 5], C'diamonds', 4], C'diamonds, 3], ['diamonds', 2], ['diamonds', 1], C'clubs', 13], C'clubs', 12], C'clubs, 11], ['clubs', 10], ['clubs', 9], C'clubs', 8], C'clubs', 7], C'clubs', 6], C'clubs', 5], C'clubs', 4], C'clubs', 3], C'clubs', 2], C'clubs', 1], C'spades', 13], C'spades', 12], C'spades', 11], C'spades', 10], C'spades, 9], ['spades', 8], C'spades', 7], 'spades', 6], C'spades', 5], 'spades', 4], C'spades, 3], C'spades, 2], C'spades', 1]]
import random import copy def deck ) t 11 1 -lst Returns a deck of cards as a list. Each element in the list is a list of a string representing the suit ("spades", "clubs", "diamonds", or rhearta and an integer representing che number of the card ( to 15) def random shuffle (lst): In I 11 (list) -> list Receives a list and returns a randomly ordered list containing all of the same elements. def reverse (1st): n In 1 (list) - list Receives a list and returns a reverse ordered list containing all of the same elements.
HINTS: Ynraarand First, you should import the random library import random then: random.sample (range (1, Max), N) return a list of N random numbers between 1 and Max
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import random
import copy

def deck():
   """Returns a deck of cards as a list"""
   suits = ["spades","clubs","diamonds","hearts"]
   res = []
   for suit in suits:
       for i in range(1,14):
           res.append([suit, str(i)])
   return res

def random_shuffle(lst):
   """Returns a randomly shuffled list with same elements."""
   res = copy.deepcopy(lst)
   random.shuffle(res)
   return res

def reverse(lst):
   """Returns a reversed ordered list with same elements"""
   res = copy.deepcopy(lst)
   res.reverse()
   return res

print(deck())


print(random_shuffle(deck()))


print(reverse(deck()))

Add a comment
Know the answer?
Add Answer to:
urgent help with python. can somone code this please and show output QUESTION: There are a variety of games possi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need a function that generates and returns a list containing all integers from 0 to...

    I need a function that generates and returns a list containing all integers from 0 to 51 (inclusive) where the integers correspond to cards in a deck like this 0 - 3:        2 clubs, diamonds, hearts, spades (in that order) 4 - 7:        3 clubs, diamonds, hearts, spades (in that order) 8 - 11:       4 clubs, diamonds, hearts, spades (in that order) 12 - 15:   5 clubs, diamonds, hearts, spades (in that order) 16 -...

  • Write in Java! Do NOT write two different programs for Deck and Card, it should be...

    Write in Java! Do NOT write two different programs for Deck and Card, it should be only one program not 2 separate ones!!!!!! !!!!!!!!!!!!!!!Use at least one array defined in your code and two array lists defined by the operation of your code!!!!!!!!!!!!!!!!!!!!! The array should be 52 elements and contain a representation of a standard deck of cards, in new deck order. (This is the order of a deck of cards new from the box.) The 2 Array lists...

  • C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification...

    C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification file) Card.cpp (class implementation file) DeckOfCards.h (class specification file) DeckOfCards.cpp (class implementation file) 200_assign6.cpp (application program) NU eelLS Seven UT Diamonds Nine of Hearts Six of Diamonds For your sixth programming assignment you will be writing a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards and an application program. Class Card should provide: a....

  • With the code given write python code that prints the probablity of getting a straight in...

    With the code given write python code that prints the probablity of getting a straight in poker when you run 10**5 trails. HELPER CODE: # We will represent cards as a string, e.g., 'AC' will be Ace of Clubs # Denominations: 2, ..., 10, 'J' = Jack, 'Q' = Queen, 'K' = King, 'A' = Ace Denominations = ['2','3','4','5','6','7','8','9','10','J','Q','K','A'] # Suits 'S' = Spades, 'H' = Hearts, 'D' = Diamonds, 'C' = Clubs Suits = ['C', 'H', 'S', 'D'] #...

  • Now, create a Deck class that consists of 52 cards (each card is an instance of...

    Now, create a Deck class that consists of 52 cards (each card is an instance of class Card) by filling in the template below. Represent the suit of cards as a string: "Spades", "Diamonds", "Hearts", "clubs" and the rank of cards as a single character or integer: 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", class Deck: def init (self): pass # Your code here. def draw (self): Returns the card at the top of the deck, and...

  • I've created a Card class and I'm asked to implement a class called DeckOfCards that stores...

    I've created a Card class and I'm asked to implement a class called DeckOfCards that stores 52 objects of the Card class. It says to include methods to shuffle the deck, deal a card, and report the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck. I also need to create a separate driver class that first outputs the populated deck to prove it...

  • bblem deals with playing cards. The Card API is given below: public class Card ( suit...

    bblem deals with playing cards. The Card API is given below: public class Card ( suit is "Clubs", "Diamonds", "Bearts", or "Spades" Gene=ination s 2", , "10" יי", ,"פ" ,"8" ,"ר" , "6" ,"5י ,-4" ,"ני- * or "A * value is the value of the card number if the card denominat, *is between 2 and 10; 11 for J, 12 for Q, 13 for K, 14 for A public Card (String suit, string denomination){} 1/returns the suit (Clubs, Diamonds,...

  • Answer the following questions and use Excel to show your work. A standard deck of playing...

    Answer the following questions and use Excel to show your work. A standard deck of playing cards consists of 52 cards. The cards in each deck consist of 4 suits, namely spades (♠), clubs (♣), diamonds (♦), and hearts (♥). Each suit consists of 13 cards, namely ace, king, queen, jack, 10, 9, 8, 7, 6, 5, 4, 3, and 2. In the game of poker, a royal flush consists of the ace, king, queen, jack, and 10 of the...

  • Suppose that we've decided to test Clara, who works at the Psychic Center, to see if...

    Suppose that we've decided to test Clara, who works at the Psychic Center, to see if she really has psychic abilities. While talking to her on the phone, we'll thoroughly shuffle a standard deck of 52 cards (which is made up of 13 hearts, 13 spades, 13 diamonds, and 13 clubs) and draw one card at random. We'll ask Clara to name the suit (heart, spade, diamond, or club) of the card we drew. After getting her guess, we'll return...

  • Suppose that we've decided to test Clara, who works at the Psychic Center, to see if...

    Suppose that we've decided to test Clara, who works at the Psychic Center, to see if she really has psychic abilities. While talking to her on the phone, we'll thoroughly shuffle a standard deck of 52 cards (which is made up of 13 hearts, 13 spades, 13 diamonds, and 13 clubs) and draw one card at random. We'll ask Clara to name the suit (heart, spade, diamond, or club) of the card we drew. After getting her guess, we'll return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT