the card value and the second letter is the card suit

Write a function comp10001huxxy_valid_table() which takes a single argument: groups, a list of lists of cards (each a 2-element string, where the first letter is the card value and the second letter is the card suit, e.g. ‘3H’ for the 3 of Hearts, ‘AS’ for the 1 of Spades), where each list of cards represents a single group on the table, and the combined list of lists represent the combined groups played to the table. Your function should return a bool, which evaluates whether the table state is valid or not. Recall from the rules of the game that the table is valid if all groups are valid, where a group can take one of the following two forms: an N -of-a-kind (i.e. three or more cards of the same value), noting that in the case of a 3-of-a-kind, each card must have a unique suit (e.g. [‘2S’, ‘2S’, ‘2C’] is not a valid 3-of-a-kind, as the Two of Spades has been played twice), and if there are 4 or more cards, all suits must be present. a run (i.e. a group of 3 or more cards, starting from the lowest-valued card, and ending with the highest-valued card, forming a continuous sequence in terms of value, and alternating in colour; note that the specific ordering of cards in the list is not significant, i.e. [‘2C’, ‘3D’, ‘4S’] and [‘4S’, ‘2C’, ‘3D’] both make up the same run.

example function calls as follows:

>>> comp10001huxxy_valid_table([]) True

>>> comp10001huxxy_valid_table([[‘AC’]]) False

>>> comp10001huxxy_valid_table([[‘AC’, ‘2S’]]) # run too short False

>>> comp10001huxxy_valid_table([[‘AC’, ‘2S’, ‘3H’]]) # run doesn’t alternate in colour False

>>> comp10001huxxy_valid_table([[‘AC’, ‘2S’, ‘4H’]]) # values not adjacent False

>>> comp10001huxxy_valid_table([[‘AC’, ‘2H’, ‘3S’]]) True

>>> comp10001huxxy_valid_table([[‘3C’, ‘AS’, ‘2H’]]) # test unsorted run True

>>> comp10001huxxy_valid_table([[‘0C’, ‘JH’, ‘QS’, ‘KH’, ‘9D’]]) True

>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’]]) # n-of-kind too short False

>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2C’]]) # same suit twice for 3-of-kind False

>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2S’, ‘2C’]]) # same suit twice for 4-of-kind False

>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2S’]]) True

>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2S’, ‘2D’]]) True

>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2S’, ‘2D’, ‘2S’]]) True

>>> comp10001huxxy_valid_table([[‘2C’, ‘2H’, ‘2S’, ‘2D’, ‘2S’], [‘0D’, ‘9C’, ‘8H’]]) True

Please answer it with simple cod

The post the card value and the second letter is the card suit appeared first on My Assignment Online.

WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
👋 Hi, how can I help?
Scroll to Top