Question: 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!!!!!!!!!

python!!!!!!!!! Problem 1: Poker Note: this problem requires fairly efficient code. Justbrute force iteration and nested for loops will take too long. Consider

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!