00:01
So for problem 25, you're asked to write a program that will pick four cards from a deck of 52 cards at random and compute the sum of those cards.
00:13
And then we're told that our program should also display the number of picks that yield a sum of 24.
00:20
So i sort of attacked those two things separately.
00:25
That's the way that i interpreted the problem, but you might have interpreted it differently.
00:32
So i started with the first part where we're going to randomly choose four cards and compute the sum of those four cards.
00:41
So i'm going to import random, which will help in choosing the cards.
00:47
And i choose to separate rank and suit at this point into two separate lists.
00:52
So we have one list, which is the ranks of all possible cards, and then another list, which is suit, which includes all of the possible suits.
01:06
I'm going to have an empty list here called cards that i'll add to as i pick my card, so i can actually print out the four cards and check if the calculated sum is correct.
01:18
And then total is going to start at zero.
01:22
And as i pick cards, i'll be adding to the total.
01:27
I'm going to start with n equal to zero, where n is the number of cards that i'm picking, and i'm going to use a while loop to do this problem.
01:39
There are other ways of doing it, but i chose to do it this way.
01:42
So while n is less than four, so while i have chosen less than four cards, card rank is going to equal random choice of rank, and card suit is going to equal random choice of suit.
01:57
First, we want to check if it's a card that we've picked before because we are assuming that we're picking four cards rather than picking cards and putting them back.
02:09
So if not, card rank of card suit in cards, so if the card that we just pick is not already in our hand, then we want to append that to our cards list to indicate that it is now in our hand.
02:30
And then for the face cards, we need to give them a number.
02:35
So if it's an ace, that should be one, a jack is 11, a queen is 12, and a king is 13...