Question
PYTHON Write a function is_straight that takes in a list of 5 cards and returns whether the ranks of the cards form a straight. Cards
PYTHON Write a function is_straight that takes in a list of 5 cards and returns whether the ranks of the cards form a straight. Cards will be specified the same way as in Problem 1. A straight is a set of cards in which the card ranks are consecutive. Card ranks go from 2 to 9, then Ten, Jack, Queen, and King. The Ace can count as the highest rank or the lowest rank when determining a straight. Suit is irrelevant when determining whether the cards form a straight. Hint: start by finding the high card, then determine if the next 4 lower ranks are present. If the high card is an Ace, check whether the other ranks are King, Queen, Jack, and Ten OR 2, 3, 4, and 5. Sample test cases: Input: ['TS', 'JS', 'QS', 'KS', 'AS'] Output: True Input: ['JS', 'KS', 'AS', 'QS', 'TS'] Output: True Input: ['4H', '5S', '6D', '8D', '9H'] Output: False Input: ['3C', '2D', '4C', 'AD', '5C'] Output: True
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started