Cut the deck

Cut the deck

Reveal a card in a short deck.

Cutting the deck is a common way to resolve draws in playing card games. One player takes any number of cards (usually approximately half) from a face down full deck and then reveals the card on the bottom of their pile. The second player then takes any card from those remaining in the deck and reveals their card.

Higher numbers beat lower numbers regardless of suit. J is 11, Q is 12, K is 13 and A is 14. The alphabetical order of the suit resolves draws. Clubs (C) is lowest followed by diamonds (D), hearts (H) and spades (S) is the highest.

In a short deck the lowest number is a 6. Therefore the 6C (the six of clubs) is the lowest card and AS (the ace of spades) is the highest card.


Write a program that asks the user to pick one of the first thirty-five cards in the deck. All the previous cards are discarded. The computer then picks one of the remaining cards. Whoever has the highest card wins. The result is output to the user.

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the `main program` so that:

  1. The random number generator uses a default seed.
  2. Copies the list of cards into a playing deck identified as "deck".
  3. Calls the `play_game` procedure.

Complete the subprogram called `play_game` that:

  1. Shuffles the playing deck.
  2. Asks the user to enter a number between 0 and 34 (representing the bottom card of their pile.)
  3. Outputs the card drawn. E.g. 8H
  4. Chooses a random card from those remaining for the computer.
  5. Outputs the card drawn. E.g. QD
  6. Calls the `output_winner` procedure with the two cards as parameters.

Complete the subprogram called `output_winner` that:

  1. Takes the two cards drawn as parameters.
  2. Calculates who won.
  3. Outputs the winner.

Hint: Modulus 9 will tell you the value of the card because there are 9 cards in each suit. In the case of draws you can look up the index of the card drawn in the cards list to know a card's relative value.

Typical inputs and outputs from the program would be:

What number card do you want to draw? 0-34 :20

You reveal the 8H

The CPU reveals the AS

CPU wins.

What number card do you want to draw? 0-34 :13

You reveal the 10D

The CPU reveals the 9S

You win!

What number card do you want to draw? 0-34 :18

You reveal the 6H

The CPU reveals the 6S

CPU wins.

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:


Run the program several times to check that your program has met the success criteria.

Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.