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

cards.py:https://www.cse.msu.edu/~cse231/Online/Labs/Lab11/cards.py lab11a.py:ht

ID: 3850977 • Letter: C

Question

cards.py:https://www.cse.msu.edu/~cse231/Online/Labs/Lab11/cards.py

lab11a.py:https://www.cse.msu.edu/~cse231/Online/Labs/Lab11/lab11a.py

Just need to do part 1. abcd of 1 should be in one code. Please try to get the output.

Part A: Using the Class Methods 1. Examine the Python statements in the file named "labl la py", then extend that program to do the following tasks: a. Display each players' hand after the first card has been played from each hand. b. Display the second card dealt to each player and compare them c. Display each players' hand after the second card has been played from each hand d. Display the last card dealt to each player and compare them. Here is the additional output after those modifcations Second card dealt to player #1: Q4 Player #1 hand: [74, 10 Second card dealt to player #2: Q Player #2 hand EK 2 8 Last card in hand of player #1 7 Last card in hand of player #2: 8+ 8* of higher rank than 7 Note on Mirmir testing: you will notice that the symbols for the suits are not printed in the Mirmir tests instead the letters hcds are used. That is because Mimir cannot handle the symbols. You do not need to do anything about that-it is built into the cards.py that we use for testing. Demonstrate your completed program to your TA. on-line students should submit the completed program (named "labila.py") for grading via the Mirmir system Do steps 2 and 3 on your own without handing in to Mirmir 2. Revise the program to use a different integer number as the argument in the invocation of function "random seed". Run the program several times and observe the results. 3. Revise the program to eliminate the invocation of function "random.seed Run the program several times and observe the results. Note: if function "random.seed" is not invoked, then the current system time is used to initialize the random number generator

Explanation / Answer

##
## Demonstrate some of the operations of the Deck and Card classes
##

import cards

# Seed the random number generator to a specific value so every execution
# of the program uses the same sequence of random numbers (for testing).

import random
random.seed( 100 )

# Create a deck of cards

my_deck = cards.Deck()


# Shuffle the deck, then display it in 13 columns

my_deck.shuffle()
print( "===== shuffled deck =====" )
my_deck.display()


# Deal five cards to each player (alternating)

print( "Dealt five cards to each player (alternating)" )
print()

player1_list=[]
player2_list=[]
for i in range( 5 ):
player1_list.append( my_deck.deal() )
player2_list.append( my_deck.deal() )

# Display each player's cards and the cards still in the deck

print( "===== player #1 =====" )
print()
print( player1_list )
print()
print( "===== player #2 =====" )
print()
print( player2_list )
print()
print( "===== remaining cards in deck =====" )
my_deck.display()


# First card dealt to Player #1

player1_card = player1_list.pop( 0 )

print( "First card dealt to player #1:", player1_card )


# First card dealt to Player #2

player2_card = player2_list.pop( 0 )

print( "First card dealt to player #2:", player2_card )

# Second card dealt to Player #1

player1_card = player1_list.pop( 0 )

print( "Second card dealt to player #1:", player1_card )
print( "Player #1 hand", player1_list)

# Second card dealt to Player #2

player2_card = player2_list.pop( 0 )

print( "Second card dealt to player #2:", player2_card )
print( "Player #2 hand", player2_list)
# Last card dealt to Player #1

player1_card = player1_list.pop( 2 )

print( "Last card dealt to player #1:", player1_card )


# Last card dealt to Player #2

player2_card = player2_list.pop( 2 )

print( "Last card dealt to player #2:", player2_card )


# Compare the ranks of the two cards

print()
if player1_card.rank() == player2_card.rank():
print( "Tie:", player1_card, "and", player2_card, "of equal rank" )
elif player1_card.rank() > player2_card.rank():
print( "Player #1 wins:", player1_card, "of higher rank than", player2_card )
else:
print( "Player #2 wins:", player2_card, "of higher rank than", player1_card )

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote