Question: from enum import Enum, auto from typing import Callable class Colour ( Enum ) : RED = auto ( ) BLUE = auto ( )
from enum import Enum, auto
from typing import Callable
class ColourEnum:
RED auto
BLUE auto
GREEN auto
YELLOW auto
def strself str:
return self.name
class ShapeEnum:
HEXAGON auto
CIRCLE auto
DIAMOND auto
RHOMBUS auto
def strself str:
return self.name
class Card:
def initself colour: Colour, shape: Shape, number: int:
self.colour colour
self.shape shape
self.number number
def getcolourself Colour:
return self.colour
def getshapeself Shape:
return self.shape
def getnumberself int:
return self.number
def reprself str:
return strselfnumber strselfcolour strselfshape
def eqself o bool:
if not isinstanceo Card:
return False
return self.colour is ogetcolour and self.shape is ogetshape and self.number ogetnumber
class Player:
def initself hand: listCard:
self.hand hand
def matchself test: CallableCard bool int:
return lencard for card in self.hand if testcard
def howmanycolourself colour: Colour int:
return self.matchlambda x: xgetcolour is colour
def howmanyshapeself shape: Shape int:
return self.matchlambda x: xgetshape is shape
def howmanynumberself number: int int:
return self.matchlambda x: xgetnumber number
def howmanycolournumberself colour: Colour, number: int int:
return self.matchlambda x: xgetcolour is colour and xgetnumber number
def howmanyshapenumberself shape: Shape, number: int int:
return self.matchlambda x: xgetshape is shape and xgetnumber number
def howmanycolourshapeself colour: Colour, shape: Shape int:
return self.matchlambda x: xgetcolour is colour and xgetshape is shape
def hascardself guess: Card bool:
return guess in self.hand
# Helper functions to get user input
def getcolour Colour:
printThe colour options are:"
print RED"
print BLUE"
print GREEN"
print YELLOW"
colourchoice inputWhich colour do you want?
colourmapping : Colour.RED, : Colour.BLUE, : Colour.GREEN, : Colour.YELLOW
return colourmapping.getcolourchoice, None
def getshape Shape:
printThe shape options are:"
print HEXAGON"
print CIRCLE"
print DIAMOND"
print RHOMBUS"
shapechoice inputWhich shape do you want?
shapemapping : Shape.HEXAGON, : Shape.CIRCLE, : Shape.DIAMOND, : Shape.RHOMBUS
return shapemapping.getshapechoice, None
def getnumber int:
return intinputEnter a number from inclusive:
# Function to handle asking questions
def askquestionplayer: Player:
printWhich question would you like to ask?"
print How many cards with a certain colour?"
print How many cards with a certain shape?"
print How many cards with a certain number?"
print How many cards with a certain colour and number?"
print How many cards with a certain shape and number?"
print How many cards with a certain colour and shape?"
questiontype inputWhich option would you like?
if questiontype :
colour getcolour
printfThe player has playerhowmanycolourcolour cards with colour colour
elif questiontype :
shape getshape
printfThe player has playerhowmanyshapeshape cards with shape shape
elif questiontype :
number getnumber
printfThe player has playerhowmanynumbernumber cards with number number
elif questiontype :
colour getcolour
number getnumber
printfThe player has playerhowmanycolournumbercolour number cards with colour colour and number number
elif questiontype :
shape getshape
number getnumber
printfThe player has playerhowmanyshapenumbershape number cards with shape shape and number number
elif questiontype :
colour getcolour
shape getshape
printfThe player has playerhowmanycolourshapecolour shape cards with colour colour and shape shape
else:
printThat is not an option, try again."
# Function to handle guessing cards
def guesscardplayer: Player, guessedcards: listCard bool:
colour getcolour
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
