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

python please Part V: War Variant #1 : Suit Rank (20 points) Complete the functi

ID: 3717509 • Letter: P

Question

python please

Part V: War Variant #1 : Suit Rank (20 points) Complete the function play with suits(), which takes two arguments, in this order. 1. player1:a player object that represents Player#1 2, player2: a Player object that represents Player #2 This function provides an alternate form of gameplay to the rules implemented in the play normal.round function. Rather than decide the winner using card ranks, the winner is decided using suits: 1. Hearts beat Spades and Diamonds CSE 101 - Spring 2018 Homework #5 Page 4 2. Spades beat Diamonds and Clubs 3. Diamonds beat Clubs 4. Clubs beat Hearts Here's an example Player 1 drew 6 Player 2 drew 24 Player 2 won the round, scoring 2 points. Wars are now caused when two cards of the same suit are drawn, as in the example below Player 1 drew Q* Player 2 drew 8 WAR! Player 1 drew K Player 2 drew 9 WAR! Player 1 drew A Player 2 drew 84 Player 1 won the round, scoring 6 points. If the two players start a war and then run out of cards, the round is considered a tie. In this case the function returns the tuple (0, 0) Hint: recall that each suit is represented using an ID number (see the suits dictionary in the war-classes. py file). You can these numbers to compare the _suit properties of two Card objects.

Explanation / Answer

As the war_classes.py file is not available, I had to use a list for the "suits" and compare them accordingly. You can even change the order of priority just by altering the position of the elements in the SUITS list.

import random

count = 0

def play_normal_round(): #compares the chosen cards
if(play_with_suits.player_1 == play_with_suits.player_2): #if 2 suits are equal
print("WAR!")
play_with_suits()
play_normal_round()

#suit chosen by player1 is greater than player2
elif(play_with_suits.player_1 > play_with_suits.player_2):
print("player 1 won the round, scoring", count, "points")
else:
print("player 2 won the round, scoring", count, "points") #suit chosen by player 2 is greater
  
def play_with_suits(): #draws the cards randomly and displays them
SUITS = ('Hearts', 'Spades', 'Diamonds', 'Clubs') #can be prioritized by changing the positions
RANKS = (2,3,4,5,6,7,8,9,10,'Jack','Queen','King','Ace')
# Player 1 drawing the card
play_with_suits.player_1 = random.choice(SUITS) #selecting a suit randomly for player 1
play_with_suits.player_1_ranks = random.choice(RANKS) #selecting a number randomly for player 1

# Player 2 drawing the card
play_with_suits.player_2 = random.choice(SUITS)
play_with_suits.player_2_ranks = random.choice(RANKS)
global count
count = count+2

#displaying the chosen cards
print ("Player1 drew",play_with_suits.player_1_ranks,play_with_suits.player_1)
print ("Player2 drew",play_with_suits.player_2_ranks,play_with_suits.player_2)

play_with_suits() #calling play_with_suits() function
play_normal_round()#calling play_normal_round() function