Answered step by step
Verified Expert Solution
Question
1 Approved Answer
python!!!!!!!!! Problem 1: Poker Note: this problem requires fairly efficient code. Just brute force iteration and nested for loops will take too long. Consider a
python!!!!!!!!!
Problem 1: Poker Note: this problem requires fairly efficient code. Just brute force iteration and nested for loops will take too long. Consider a standard deck of 52 playing cards. A poker hand consists of five distinct cards. A flush consists of five cards of the same suit, of any ranks. A straight consists of five consecutive cards, not necessarily of the same suit. Aces can be either low or high (so Ace-5 and 10-Ace are both allowed), but otherwise no wrapping around is allowed (so Jack, Queen, King, Ace, 2 is not a straight). A hand that is both a flush and a straight is considered to be NEITHER; it is called a straight flush. 2a. Write a function flush that takes as input a list of five cards, tests whether it is a flush (Note: straight flush is not a flush!) and return a boolean value. If the entry is anything other than five distinct cards, it should return (not print!) the message "This is not a valid poker hand". 2b. Write a function straight that takes as input a list of five cards, tests whether it is a straight (Note: straight flush is not a straight!) and return a boolean value. If the entry is anything other than five distinct cards, it should return (not print!) the message This is not a valid poker hand". 2c. Use your previous answers to count the number of possible flushes and straights in a standard deck, by enumerating all hands and testing each one with the functions you already wrote. Make sure to use varaibles num_of_flushes and num_of_straights to count them separately. At the end, num_of_flushes and num_of_straights shall contain the number of flushes and straights separately. Which one occurs more often? (Hint: You may find this helpful https://docs.python.org/2/library/itertools.html) Problem 1: Poker Note: this problem requires fairly efficient code. Just brute force iteration and nested for loops will take too long. Consider a standard deck of 52 playing cards. A poker hand consists of five distinct cards. A flush consists of five cards of the same suit, of any ranks. A straight consists of five consecutive cards, not necessarily of the same suit. Aces can be either low or high (so Ace-5 and 10-Ace are both allowed), but otherwise no wrapping around is allowed (so Jack, Queen, King, Ace, 2 is not a straight). A hand that is both a flush and a straight is considered to be NEITHER; it is called a straight flush. 2a. Write a function flush that takes as input a list of five cards, tests whether it is a flush (Note: straight flush is not a flush!) and return a boolean value. If the entry is anything other than five distinct cards, it should return (not print!) the message "This is not a valid poker hand". 2b. Write a function straight that takes as input a list of five cards, tests whether it is a straight (Note: straight flush is not a straight!) and return a boolean value. If the entry is anything other than five distinct cards, it should return (not print!) the message This is not a valid poker hand". 2c. Use your previous answers to count the number of possible flushes and straights in a standard deck, by enumerating all hands and testing each one with the functions you already wrote. Make sure to use varaibles num_of_flushes and num_of_straights to count them separately. At the end, num_of_flushes and num_of_straights shall contain the number of flushes and straights separately. Which one occurs more often? (Hint: You may find this helpful https://docs.python.org/2/library/itertools.html)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