cant seem to get this code to work. It is supposed to be a card game where I draw for me then for the computer: from Button import Button import random ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"] suits = ["Spades", "Hearts", "Diamonds", "Clubs"] image_filenames = ["spade.png", "heart.png", "diamond.png", "club.png"]         images = [] blank_image = None player_one_suit = None player_two_suit = None player_one_rank = "-" player_two_rank = "-" game_result = "" btn = None def cut():     rank = random.choice(ranks)     suit_index = random.randrange(4)     return rank, suit_index def setup():     global btn, images, blank_image     global player_one_rank, player_two_rank, player_one_suit, player_two_suit          for i in range(len(image_filenames)):         images.append(loadImage(image_filenames[i]))         images[i].resize(50,50)     blank_image = loadImage("blank.png")     player_one_suit = blank_image     player_two_suit = blank_image     size(400,400)     btn = Button(width /2, height*0.75, 100, 40, "You Cut")      def draw():     global btn, game_reslut     global player_one_rank, player_two_rank, player_one_suit, player_two_suit     background(127)     btn.show()     textSize(70)     image(player_one_suit, width/4, height/4)     image(player_two_suit, width*0.75, height/4)     image(player_one_rank, width*0.18, height/4+20)     image(player_two_rank, width*0.68, height/4+20)     textSize(30)     text(game_result, width*0.5, height*0.9)      def mouseClicked():     global btn          if btn.collide(mouseX, mouseY):         take_turn()          def keyTyped():     if key == 't' or key == 'T':         print("key=" + key)         take_turn() def take_turn():     global btn, suits, ranks, images, blank_image, game_result     global player_one_rank, player_two_rank, player_one_suit, player_two_suit          if btn.text == "You Cut":         rank, suit_index = cut()         print(rank + ' ' + suits[suit_index])         player_two_rank = rank         player_two_suit = images[suit_index]         btn.text = "Computer Cuts"         btn.W = 145          elif btn.text == "Computer Cuts":         rank, suit_index = cut()         print(rank + ' ' + suits[suit_index])         player_two_rank = rank         player_two_suit = images[suit_index]         btn.text = "Reset"         btn.W = 60 any advice?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I cant seem to get this code to work. It is supposed to be a card game where I draw for me then for the computer:

from Button import Button
import random

ranks = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
suits = ["Spades", "Hearts", "Diamonds", "Clubs"]

image_filenames = ["spade.png", "heart.png", "diamond.png", "club.png"]        
images = []
blank_image = None

player_one_suit = None
player_two_suit = None
player_one_rank = "-"
player_two_rank = "-"

game_result = ""

btn = None

def cut():
    rank = random.choice(ranks)
    suit_index = random.randrange(4)
    return rank, suit_index

def setup():
    global btn, images, blank_image
    global player_one_rank, player_two_rank, player_one_suit, player_two_suit
    
    for i in range(len(image_filenames)):
        images.append(loadImage(image_filenames[i]))
        images[i].resize(50,50)
    blank_image = loadImage("blank.png")
    player_one_suit = blank_image
    player_two_suit = blank_image
    size(400,400)
    btn = Button(width /2, height*0.75, 100, 40, "You Cut")
    
def draw():
    global btn, game_reslut
    global player_one_rank, player_two_rank, player_one_suit, player_two_suit
    background(127)
    btn.show()
    textSize(70)
    image(player_one_suit, width/4, height/4)
    image(player_two_suit, width*0.75, height/4)
    image(player_one_rank, width*0.18, height/4+20)
    image(player_two_rank, width*0.68, height/4+20)
    textSize(30)
    text(game_result, width*0.5, height*0.9)
    
def mouseClicked():
    global btn
    
    if btn.collide(mouseX, mouseY):
        take_turn()
        
def keyTyped():
    if key == 't' or key == 'T':
        print("key=" + key)
        take_turn()

def take_turn():
    global btn, suits, ranks, images, blank_image, game_result
    global player_one_rank, player_two_rank, player_one_suit, player_two_suit
    
    if btn.text == "You Cut":
        rank, suit_index = cut()
        print(rank + ' ' + suits[suit_index])
        player_two_rank = rank
        player_two_suit = images[suit_index]
        btn.text = "Computer Cuts"
        btn.W = 145
    
    elif btn.text == "Computer Cuts":
        rank, suit_index = cut()
        print(rank + ' ' + suits[suit_index])
        player_two_rank = rank
        player_two_suit = images[suit_index]
        btn.text = "Reset"
        btn.W = 60

any advice?

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education