Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Project lab09b.py cards_B.py import random AWN class Card( object ) : Model a playing card. un # Rank is an int (1-13), where aces

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Project lab09b.py cards_B.py import random AWN class Card( object ) : """ Model a playing card. "un # Rank is an int (1-13), where aces are 1 and kings are 13. 8 # Suit is an int (1-4), where clubs are 1 and spades are 4. 9 # Value is an int (1-10), where aces are 1 and face cards are 10. 10 11 # List to map int rank to printable character (index 0 used for no rank) 12 rank_list = ['x' , 'A' , '2' , '3' , '4' , '5' , '6', '7', '8' , '9' , '10' , 'J', 'Q' ,'K'] 13 14 # List to map int suit to printable character (index 0 used for no suit) 15 # 1 is clubs, 2 is diamonds, 3 is hearts, and 4 is spades 16 suit_list = ['x' , '\\u2663' , '\\u2666', ' \\u2665' , ' \\u2660'] 17 #suit_list = ['x', 'c', 'd', 'h', 's'] 18 19 def __init__( self, rank=0, suit=0 ) : 20 """ Initialize card to specified rank (1-13) and suit (1-4). "ww 21 self. __rank = 0 22 self. __suit = 0 23 self. __face_up = None 24 # Verify that rank and suit are ints and that they are within 25 # range (1-13 and 1-4), then update instance variables if valid. 26 if type (rank) == int and type(suit) == int: 27 if rank in range (1, 14) and suit in range(1, 5) : 28 self. __rank = rank 29 self. __suit = suit 30 self. __face_up = True 31 32 def rank( self ) : 33 """ Return card's rank (1-13). "un 34 return self. __rank 35 36 def value( self ) : 37 " Return card's value (1 for aces, 2-9, 10 for face cards). " 38 # Use ternary expression to determine value. 39 return self. __rank if self. __rank

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions